字符串处理基础(一)反转,循环移动
2014-04-25 23:39
141 查看
#pragma once using namespace std; void inverse(char *p); void printString(char *p); void rightMove(char *p,int n); void inverse2(char *p); void inverse(char *p) { if (p==NULL||*p=='\0') { return; } char *head=p; char *last=p; while((*last)!='\0') { last++; } last--; char temp; while(head<=last) { temp=*head; *head=*last; *last=temp; head++; last--; } } void printString(char *p) { if (p==NULL) { return; } while(*p!='\0') { cout<<*p; ++p; } } void rightMove(char *p,int n) { if (p==NULL||n<0) { return; } int len=0; char *last=p; while(*last!='\0') { len++; last++; } last--; char temp; int nn=n%len; for(int i=1;i<=nn;i++) { temp=p[len-1]; for(int i=len-1;i>=1;--i) { p[i]=p[i-1]; } p[0]=temp; } } //给定字符串"we;tonight;you;",编码实现输出"ew;thginot;uoy;" //给定字符串"we;tonight;you",编码实现输出"ew;thginot;uoy" void inverse2(char *p) { if (p==NULL||*p=='\0') { return; } char *first=p; char *last=p; while(*last!=';'&&*last!='\0') { last++; } last--; char *next=last+2; while(first<last) { char temp=*first; *first=*last; *last=temp; first++; last--; } inverse2(next); }
相关文章推荐
- C#基础---C#如何对Json字符串处理
- c#基础之字符串处理
- 20161216C语言基础17_字符串处理函数之fgets与gets
- 20161216C语言基础18_字符串处理函数
- c#基础--字符串的处理_string类
- Linux20-shell编程基础、数值计算、字符串处理
- 字符串循环右移动n位
- 2016-3-12 linux基础学习——字符串比较、循环
- 20161216C语言基础18_字符串处理函数
- HDU 1013 Digital Roots 数字根 字符串处理基础题
- 字符串相关操作 拷贝,循环移动
- hdu 4891 跳出循环之后可能存在还为处理的值,字符串的个数可能超过long long
- Python基础之字符串处理方法的总结
- 黑马程序员——C基础之字符串处理函数
- 字符串循环移动
- C#基础技巧--字符串处理函数
- JavaScript基础——处理字符串
- Python基础概念_8_字符串处理
- PHP基础知识 - 字符串处理函数
- java基础之字符串反转