HDU 1062 Text Reverse
来源:互联网 发布:小学奥数 知乎 编辑:程序博客网 时间:2024/04/27 18:33
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18063 Accepted Submission(s): 6845
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.
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
3olleh !dlrowm'I morf .udhI ekil .mca
Sample Output
hello world!I'm from hdu.I like acm.
原字符串不动,然后检测出每个单词,分别倒置,水题吧。
下面是AC代码。
#include<iostream>#include<algorithm>#include<sstream>#include<stack>#include<vector>using namespace std;void rev(string &str,int s,int e){ while(s<=e) swap(str[s++],str[e--]);}int main(){ int t; string s,x; cin>>t; getline(cin,s);//吸收回车符 while(t--) { bool flag=0; getline(cin,s); int start; for(int i=0;i<s.size();i++) { if((i==0&&s[i]!=' ')||(s[i]!=' '&&s[i-1]==' ')) start=i; else if(s[i]!=' '&&s[i+1]==' ') rev(s,start,i); } if(s[s.size()-1]!=' ') rev(s,start,s.size()-1); cout<<s<<endl; } return 0;}
0 0
- hdu 1062 Text Reverse
- hdu 1062 Text Reverse
- HDU 1062 TEXT REVERSE
- Hdu 1062 - Text Reverse
- hdu 1062 Text Reverse
- HDU 1062 Text Reverse
- hdu 1062 Text Reverse
- HDU 1062 Text Reverse
- HDU 1062 - Text Reverse
- hdu 1062 Text Reverse
- hdu 1062 Text Reverse
- Text Reverse(hdu 1062)
- hdu 1062 Text Reverse
- HDU 1062 Text Reverse
- hdu 1062 text reverse
- HDU 1062 Text Reverse
- HDU 1062 Text Reverse
- hdu 1062 Text Reverse
- ZOJ Problem Set - 1240 IBM Minus One
- Android 事件传递
- 今天开始
- ExtJs4 中的定时任务实现
- Android 学习论坛博客及网站推荐及源码下载 .
- HDU 1062 Text Reverse
- Patrol Robot UVa1600巡逻机器人
- JSON
- HBuilder 配置Python、PHP开发环境
- 1.3 barn1
- Tomcat并发数优化的方法总结
- 计算cpu利用率和内存利用率
- ios百度地图实现多标记
- 1012. 数字分类