杭电 hdu 1062 Text Reverse
来源:互联网 发布:淘宝权重怎么提升 编辑:程序博客网 时间:2024/06/04 01:25
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 26287 Accepted Submission(s): 10214
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.HintRemember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
str.find(' ’,n) //从n开始寻找出现' '字符的位置。
str.find_find_last_of(' ') //寻找最后出现‘ ’字符的位置。
reverse(str.begin()+n,str.begin()+str.find(' ',n)); //string中从n这个位置(str.begin()+n),到n位置后面 首次出现' '字符的位置(str.begin()+str.find(' ',n))的这一段字符串中的所有字符逆转,也就是反序排列。
#include <iostream> #include <string> using namespace std; int main() { string str; int c,i,n; cin>>c; getchar(); while(c--) { getline(cin,str); n = 0; while(str.find(' ',n) != std::string::npos) { reverse(str.begin()+n,str.begin()+str.find(' ',n)); n = str.find(' ',n) +1; while(str[n] == ' ') n++; } reverse(str.begin() + str.find_last_of(' ') + 1,str.end()); cout<<str<<endl; } return 0; }
0 0
- 杭电 HDU 1062 Text Reverse
- 杭电 hdu 1062 Text Reverse
- 杭电1062-Text Reverse
- 杭电1062 Text Reverse
- 【杭电】[1062]Text Reverse
- 杭电ACM 1062: Text Reverse
- 杭电1062 之 Text Reverse
- 杭电ACM 1062: Text Reverse
- 杭电OJ1062 Text Reverse
- 杭电OJ1062-Text Reverse
- 杭电acm1062 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
- UVALive 2034 Hot or Cold?【数学】
- iOS byte截取 socket解析
- Qt中文件读取的几种方式
- iOS工程准备工作
- 7.18-7.24学习小结
- 杭电 hdu 1062 Text Reverse
- Android学习笔记033之数据存储—SharedPreference
- powershell
- linux系统下多用户的操作
- HDU 1290 献给杭电五十周年校庆的礼物
- HDFS 冗余数据块的自动删除
- app资源目录
- avoiding Type 3 E-Mail symbol (\Letter)
- Spring使用Cache