1. 程式人生 > >pseudocode of zigzag conversion

pseudocode of zigzag conversion

pre posit pattern min make isp struct should pos

1.Title : The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R
And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows:
string convert(string text, int nRows);
 convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".

2.pseudocode :

 1 creat data structure:
 2     the given number of rows  →  nRows;
 3     the given text string  →  s;
 4     stringBuffer[] to restore result  →  sb;
 5 set char position index i = 0;row position index j = 0;combing outcome index k = 1;
6 while i < the length of s,then 7 for each j from 0 to (nRows - 1) 8 append the ith char of s to sb[j]; 9 i++; 10 end 11 for each j from (nRows - 2) to 1 12 append the ith char of s to sb[j]; 13 i++; 14 end 15 end 16 //form a united outcome 17 for each k from 1 to (nRows - 1)
18 append sb[k] to sb[0]; 19 end 20 terminate and output sb[0];

pseudocode of zigzag conversion