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];
 

最新文章

  1. ajax异步请求
  2. 【Net跨平台第一步】逆天带你零基础Linux入门【更新完毕】
  3. WinForm中使用XML文件存储用户配置及操作本地Config配置文件(zt)
  4. Eclipse JAVA文件注释乱码
  5. HDU1004之总是wa的细节问题
  6. 自定义泛型N维空间数组
  7. Uva11134 Fabled Rooks
  8. 中文web font技术及方案
  9. mksquash_lzma-3.2 编译调试记录
  10. My.Ioc 代码示例——Lifetime 和 ILifetimeScope
  11. MVC布局页占位符@RenderSection(&quot;bscript&quot;, false)
  12. JS对象深度克隆
  13. javamail+ical4j发送会议提醒
  14. C# 设置Excel数据自适应行高、列宽的2种情况
  15. Linq、Lambda表达式详细总结(转)
  16. C#中的Cookie
  17. Java代码优化小结(二)
  18. php .htaccess 伪静态
  19. 使用Pandas_UDF快速改造Pandas代码
  20. 【Bootloader】bootloader启动过程分析

热门文章

  1. MPLS LDP随堂笔记2
  2. Beta阶段事后诸葛亮分析
  3. 201521123042《Java程序设计》 第7周学习总结
  4. 201521123061 《Java程序设计》第五周学习总结
  5. 201521123109《java程序设计》第四周学习总结
  6. 201521123015 《Java程序设计》第3周学习总结
  7. python学习笔记1.2
  8. JQUERY选中问题
  9. 单例模式(Singleton)看了就懂
  10. 纳税服务系统【用户模块之使用POI导入excel、导出excel】