HDU1062 Text Reverse
2016-04-03 13:01
423 查看
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25361 Accepted Submission(s): 9817
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
3 olleh !dlrow m'I morf .udh I ekil .mca
Sample Output
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.
这题和HDU 1321其实是一样的:http://acm.hdu.edu.cn/showproblem.php?pid=1321
可以看我的博客http://blog.csdn.net/xu_fish/article/details/51049241写的:
直接给出AC代码:
#include<iostream> #include<cstring> #include<string> using namespace std; void REVERSE(string &s1) { int len; char ss[1005]; len = s1.length(); int j = len - 1; for (int i = 0; i < len; i++,j--) { ss[j] = s1[i]; } s1.clear(); for (int i = 0; i < len; i++, j--) { s1 += ss[i]; } } int main() { string str, s1; char c; int n; cin >> n; getchar(); while (n--) { for (int i = 0;;i++) { scanf("%c", &c); if (c==' '&&c!='\n') { REVERSE(s1); s1 += c; str += s1; s1.clear(); } else if (c != '\n') { s1 += c; } else if (c == '\n') { REVERSE(s1); str += s1; s1.clear(); break; } } cout << str << endl; str.clear(); } return 0; }
相关文章推荐
- java设计模式之门面模式
- HTML表格使用
- The 14th UESTC Programming Contest Final I - Intersection 计算几何、积分、精度
- 补间动画(Tween Animation)
- 元素插入顺序表
- Angular 根据 service 的状态更新 directive
- Tsinsen A1102 字符串编辑
- cloudera安装报错 socket.gaierror: [Errno -2] Name or service not known
- 守护神 Supervisor
- C# TextBox常用方法总结
- VS2010 恢复默认设置
- Java web 学习之jsp—javabean
- 自定义函数分块实现功能
- iOS UIImage 转NSString
- HDU1073 Online Judge
- IAP15L2K61S2新建工程与点灯 -- 慕司板IAP15
- 复习——查看历史命令前十
- Light OJ 1180 Software Company (二分+DP)
- socket函数
- JavaScript之jQuery-4 jQuery事件(页面加载后执行、事件处理、事件冒泡、事件对象、模拟操作)