翻转字符串
2015-11-26 21:15
316 查看
例如,输入"I am a student.",经过字符串翻转之后,输出"student. a am I"。
思路:先将"I am a student."放入到字符串数组str[]中,然后将所有字符进行逆序翻转,得到".tneduts a ma I",然后针对每个单词(以空格为划分标准)进行翻转,可得结果。
思路:先将"I am a student."放入到字符串数组str[]中,然后将所有字符进行逆序翻转,得到".tneduts a ma I",然后针对每个单词(以空格为划分标准)进行翻转,可得结果。
#include<stdio.h> int main() { char str[]="I am a student."; char *p,*q;p=q=str; printf("%s\n",str); while(*q!='\0') q++; q--; while(p<=q) { char temp=*p;*p=*q;*q=temp; p++;q--; } printf("%s\n",str); char *next;p=q=next=str; while(*next!='\0') { if(*next==' ') { q--; while(p<=q) { char temp=*p;*p=*q;*q=temp; p++;q--; } //p=++next;q=next; p=q=++next; } next++;q++; } printf("%s\n",str); return 0; } //I am a student.翻转字符串之后变成student. a am I
相关文章推荐
- hdu1005 循环节||矩阵快速幂取模
- [Unity框架]PureMVC基础
- Android基础--ConnectivityManager检查网络连接
- 软件测试W方法
- 关于在vs2013中的一个错误
- Android篇 ListView 优化笔记
- 4.5方法参数
- 使用SndPlaySound从内存中播放WAV
- 基于int的Linux的经典系统调用实现
- [连载]《C#通讯(串口和网络)框架的设计与实现》- 5.串口和网络统一IO设计
- 约瑟夫报数出列题
- 《leetCode》:Reverse Linked List II
- 图像的频率域高斯低通滤波
- XMPP协议实现原理介绍
- MIT算法导论-第二讲-渐进符号,递归及解法
- Saltstack的Grains和Pillar比较
- android canvas详解
- spring bean 的生存范围 单例 还是原型
- POJ3041Asteroids(最小点覆盖+有点小抽象)
- android学习ScrollView的使用