HDU 1062 字符串翻转 (水题)
2016-01-15 15:57
393 查看
Problem Description
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.
Input
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.
Output
For each test case, you should output the text which is processed.
Sample Input
Sample Output
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.
Input
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.
Output
For each test case, you should output the text which is processed.
Sample Input
3 olleh !dlrow m'I morf .udh I ekil .mca
Sample Output
hello world! I'm from hdu. I like acm.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; char str[1111]; int main() { char ch; int p,i,j; int t; cin>>t; getchar(); while(t--) { p=0; while(scanf("%c",&ch)) { if(ch==' ') { str[p]='\0'; for(int i=p-1;i>=0;i--) cout<<str[i]; cout<<" "; p=0; } else if(ch=='\n') { for(int i=p-1;i>=0;i--) cout<<str[i]; cout<<endl; break; } else { str[p++]=ch; } } } return 0; }
相关文章推荐
- Bugzilla使用手册
- xcode7代码调优工具Instruments使用
- C# 中dataTable中的数据批量增加至数据表中
- Thinkphp 后台返回JSON,前台转化为对象
- 检测到在集成的托管管道模式下不适用的 ASP.NET 设置
- tf-idf最通俗的讲法
- XSUPERSMS COME ON
- Linux基本命令――系统运行级别
- 给我一个寒假,我就能撬动未来!
- 异常:“严重: The web application [] appears to have started a thread named [Thread-”
- 通过硬件层提高Android动画的性能
- 为SM30视图添加按钮
- Android UI基础之 ExpanableListView 的实现
- SNMP口令详解
- 开启Java博客
- Mybatis/ibatis代码生成
- javascript数组去掉重复项
- Android中比较常见的Java super关键字
- Storm架构
- (java)Sudoku Solver