In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to realize Z-shaped transformation and arrangement in C language". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Topic link: Z glyph transformation
Method one
-- finding rules to simulate the array
The topic requires the construction of a Z-type matrix from left to right.
Through the analysis, we can see the characteristics of this Z matrix.
The Z-type matrix is composed of orange and green parts in the picture, and the Z-type matrix is composed of one by one with the same period.
There is a case that requires special discussion: when the matrix has only one line, the original character is returned directly.
The rest of the situation is satisfactory.
The composition of its period satisfies the following law:
Fill in the matrix row number of r characters down in the first column, and then fill in one character in each of the (rmae2) columns on the upper right. The period t=r+r-2=2*r-2 of the Z-type matrix, each cycle occupies the Rmur1 column of the matrix, with a total character length of len/t cycles (the last period is regarded as a full cycle).
So create a two-dimensional matrix with r rows and c columns (here you need an extra period when calculating the columns, because the calculation of division will strip out the remainder). At the beginning, fill in the characters from the position of (0Cool 0), and determine whether to move up or down by judging the size of I% t and rmae1.
There are two situations:
I%t=r-1: indicates that the first column has been filled out, so you need to fill in the characters to the upper right, so you need to move one bit to the right and one bit up.
When a cycle is finished, it goes back to the first column of the new cycle.
Iterate through the matrix again, adding the location where the characters are stored into a new string.
Class Solution {public: string convert (string s, int numRows) {if (numRows==1 | | numRows > = s.size ()) / / Special case to exclude the number of rows of return s; int / matrices / number of rows of matrices / number of characters contained in cycles int len=s.size (); / / length of string int c = (len+t) / t* (rmur1) / / the number of two-dimensional matrix columns vector v1 (rjol string (cMago 0)); for (int iMago, Xerox 0meme yobo Tinci)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.