哈理工OJ 2305 Reversed Word(文字翻转stack)
来源:互联网 发布:oracle认证 java 编辑:程序博客网 时间:2024/06/13 00:13
题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2305
Reversed Word
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 55(22 users) Total Accepted: 25(21 users) Rating: Special Judge: No
Description
Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.
Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!
Input
Multiple test cases. The first line contains a positive integer T (T <= 1000), indicates the number of test cases.
For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.
Output
One line per case, the translated sentence.
Sample Input
2
eno owt eerht
abcde
Sample Output
one two three
edcba
Source
“尚学堂杯”哈尔滨理工大学第六届程序设计竞赛
【思路分析】用栈存一下就OK了,遇到空格的时候先把栈里的东西都输出,然后再输出空格。
【AC代码】
#include<cstdio>#include<cstring>#include<algorithm>#include<stack>using namespace std;char str[10005];int main(){ int t; scanf("%d\n",&t); while(t--) { stack<char>s; gets(str); int len=strlen(str); for(int i=0; i<len; i++) { if(str[i]!=' ') { s.push(str[i]); } else { while(!s.empty()) { printf("%c",s.top()); s.pop(); } printf(" "); } } while(!s.empty()) { printf("%c",s.top()); s.pop(); } printf("\n"); } return 0;}
- 哈理工OJ 2305 Reversed Word(文字翻转stack)
- 哈理工OJ 1743 Word Search (深搜dfs)
- hrbust 哈理工oj 1743 Word Search【DFS过】
- 哈理工OJ 2304 Julyed(水题)
- hrbust 哈理工oj 1633 word!word!【欧拉路、欧拉回路的有向图判断】
- 哈理工OJ 2179(深搜)
- 哈理工 oj 1161 Leyni
- 哈理工OJ 1692【水题】
- 哈理工oj 2317 Game
- 哈理工oj 2002 幂集
- Time(山东理工OJ)
- 哈理工OJ 1909 理工门外的树(思维题目)
- 哈理工oj 1348 最短路径 (floyd算法)
- 哈理工 OJ Fire Maze(2次bfs)
- 哈理工OJ 1652(思维题)1652 小球移动.
- 哈理工OJ 1959 森林木(并查集)
- 哈理工OJ 1161 Leyni(线段树)
- 哈理工OJ 2223 水题(用到了优先队列)
- 简单线段树模板
- HDU1159 Common Subsequence(最长公共子序列LCS)
- isstringstream——WOW!Amazing!
- c++ 异常处理(1)
- Hibernate中1+N问题以及解决方法
- 哈理工OJ 2305 Reversed Word(文字翻转stack)
- insmod: error inserting '***.ko': -1 Invalid parameters 真正原因以及解决方法
- 微信小程序-出现脚本错误或者未正确调用 Page()
- Oracle数据库动态注册和参数local_listener的使用
- box-shadow如何显示在它后面元素上面?
- Ubuntu网络配置——vlan+bonding
- 1.2 用两个队列实现一个栈
- java SLF4J 使用其他的 log框架
- MySQL在线学习1