首页 > 编程知识 正文

pseudocode of ***

时间:2023-05-05 01:52:26 阅读:235373 作者:3995

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 NA P L S I I GY 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 end11 for each j from (nRows - 2) to 112 append the ith char of s to sb[j];13 i++;14 end15 end16 //form a united outcome17 for each k from 1 to (nRows - 1)18 append sb[k] to sb[0];19 end20 terminate and output sb[0];  

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。