HDU 1062 Text Reverse(字符串)
2016-02-24 14:04
429 查看
Text Reverse
[align=left]Problem Description[/align]Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
[align=left]Input[/align]
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
[align=left]Output[/align]
For each test case, you should output the text which is processed.
[align=left]Sample Input[/align]
3
olleh !dlrow
m'I morf .udh
I ekil .mca
[align=left]Sample Output[/align]
hello world!
I'm from hdu.
I like acm.
Hint
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
[align=left]Wrong Answer[/align]
用sstream去做,感觉挺对的啊,却一直PE。
另外HDU最近有点抽啊。
#include <cstdio> #include <iostream> #include <sstream> #include <string> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <vector> #define PI acos(-1.0) #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) #define msd memset(dp,0,sizeof(dp)) using namespace std; //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); //freopen("out.txt","w",stdout); #endif // LOCAL //ios::sync_with_stdio(false); int N; cin>>N; getchar(); while(N--) { char a[1001]; char b[1001]; gets(a); for(int i=0,as=strlen(a),cur=0;i<as;i++) { b[cur++]=a[i]; if(a[i]==' ') { for(int j=cur-2;j>=0;j--) printf("%c",b[j]); printf(" "); cur=0; } if(i==as-1) { for(int j=cur-1;j>=0;j--) printf("%c",b[j]); printf("\n"); } } } return 0; }
View Code
相关文章推荐
- CentOS 6.5配置本地YUM源
- Web之二 jQuery
- 自定义Toast的实现
- 数据结构之队列(四)
- 删除我的电脑中的顽固图标
- word2010无法打开文件时的一点对策
- 常用eclipse快捷键总结(后续会用增加)
- qt5-qmake
- 使用按钮控制 动态地图服务层定义
- 数组转集合
- EventBus3.0使用笔记(详细)
- TextView加下划线
- 谷歌移动广告Unity插件
- 微信企业号开发:UserAgent
- CentOS 6.5 安装 MySQL 5.6.17 并修改MySQL的root用户密码
- 如何才能够成为一名优秀的中国企业家
- 你需要明白的脏读,不可重复读,幻读(顶)
- Tomcat7 部署CGI程序
- eoiioe linux下解压命令大全
- JAVA-表格里的c:foreach使用及数字总计