编程之美的2.17,数组循环移位 & 字符串逆转(反转) Hello world Welcome => Welcome world Hello
2013-12-17 12:28
387 查看
代码如下:(类似于编程之美的2.17,数组循环移位)
staticvoidMain(string[]args) { stringinput="HelloWorldWelcome"; char[]tempArray=input.ToCharArray(); stringresult=RightShift(tempArray,0,tempArray.Length-1); } publicstaticstringRightShift(char[]arrary,intstartIndex,intendIndex) { Reverse(arrary,0,endIndex); startIndex=endIndex=0; while(startIndex<arrary.Length-1) { if(arrary[startIndex]=='') { startIndex++; endIndex++; continue; } elseif(arrary[endIndex]=='') { intcurrentIndex=endIndex; Reverse(arrary,startIndex,endIndex-1); startIndex=endIndex=currentIndex; } elseif(endIndex==arrary.Length-1) { intcurrentIndex=endIndex; Reverse(arrary,startIndex,endIndex); startIndex=endIndex=currentIndex; } else { endIndex++; } } StringBuilderbuilder=newStringBuilder(); foreach(chariteminarrary) { builder.Append(item); } returnbuilder.ToString(); } publicstaticvoidReverse(char[]arrary,intstart,intend) { while(start<end) { chartemp=arrary[start]; arrary[start]=arrary[end]; arrary[end]=temp; start++; end--; } }
相关文章推荐
- 编程之美 2.17 数组循环移位
- 编程之美-2.17 数组移位循环
- 每天学习一点编程(14)(数组/字符串循环移位)
- [编程之美] PSet2.17 数组循环移位
- 编程之美---->字符串移位包含问题
- 编程之美-2.17-数组循环移位
- 字符串翻转集合, case1, hello world->world hello; case2, hello world->olleh dlrow
- 数组循环移位O(n) AND 按单词反转字符串
- Java笔记1 Java编程基础<2>循环语句、函数(重载)、变量和数组的内存结构
- 编程之美 2.17 数组循环移位
- 编程之美 2.17 数组循环移位
- 读书笔记之编程之美 - 2.17 数组循环移位
- 字符串翻转集合, case1, hello world->world hello; case2, hello world->olleh dlrow
- Shell 编程详解之字符串和数组<三>
- 编程之美2.17 数组循环移位
- swift 字符串,数组,字典 的那些事<二>
- C语言根据特定的符号分割字符串 如:字符串"a,bbb,ccc"->数组[a,bbb,ccc]
- Linq学习__03__数据源是IEnumerable<T> 变量,Concat,匿名类,数组下标,返回字符串,group by,orderby
- 编程实现:从字符中获取连续数组序列,如字符串"a1dl2iad9j3la5kudp7u9pn4blj8ap5u3e6ml9a"中可以得到的连续数字序列为1234556.【注】:只考虑一位,因此最长的数
- <笔试><面试>编写一个排序函数,实现,既可以排序整形数组,又可以排序字符串。