pseudocode of zigzag conversion
2024-09-29 12:43:02
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 :
creat data structure: the given number of rows → nRows; the given text string → s; stringBuffer[] to restore result → sb; set char position index i = 0;row position index j = 0;combing outcome index k = 1; while i < the length of s,then for each j from 0 to (nRows - 1) append the ith char of s to sb[j]; i++; end for each j from (nRows - 2) to 1 append the ith char of s to sb[j]; i++; end end //form a united outcome for each k from 1 to (nRows - 1) append sb[k] to sb[0]; end terminate and output sb[0];
最新文章
- ajax异步请求
- 【Net跨平台第一步】逆天带你零基础Linux入门【更新完毕】
- WinForm中使用XML文件存储用户配置及操作本地Config配置文件(zt)
- Eclipse JAVA文件注释乱码
- HDU1004之总是wa的细节问题
- 自定义泛型N维空间数组
- Uva11134 Fabled Rooks
- 中文web font技术及方案
- mksquash_lzma-3.2 编译调试记录
- My.Ioc 代码示例——Lifetime 和 ILifetimeScope
- MVC布局页占位符@RenderSection(";bscript";, false)
- JS对象深度克隆
- javamail+ical4j发送会议提醒
- C# 设置Excel数据自适应行高、列宽的2种情况
- Linq、Lambda表达式详细总结(转)
- C#中的Cookie
- Java代码优化小结(二)
- php .htaccess 伪静态
- 使用Pandas_UDF快速改造Pandas代码
- 【Bootloader】bootloader启动过程分析