码迷,mamicode.com
首页 > 其他好文 > 详细

pseudocode of zigzag conversion

时间:2017-10-17 15:21:21      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:write   ext   class   pattern   tco   may   pen   doc   int   

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

标签:write   ext   class   pattern   tco   may   pen   doc   int   

原文地址:http://www.cnblogs.com/wenj17/p/7680775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!