Title |
说反话 |
Time |
1000 |
Memory |
65536 |
Submissions |
248 |
Accepted |
55 |
Description |
大神众屌丝膜拜 觉得自己最近年老智力衰退了,想锻炼一下自己的反映速度,作为 ACM 的老队长,ACM 队员表示很乐意帮助他。 |
Input |
输入只有一行,一个由多个单词组成的英文句子,两个单词之间由一个或多个空格隔开,单词中没有特殊符号。每个单词不超过 50 个字符,一共不超过 500 个单词,句子总长不超过 50000。 |
Output |
输出每个单词反转之后的字符串,不要改变单词的大小写,空格与原文保持一致。 |
Sample Input |
hello World |
Sample Output |
olleh dlroW |
Hint |
none |
Source |
2016 SAU ACM |
# include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace std; int main() { string s; int head, pos; getline(cin, s); pos = s.find(" ", 0); head = 0; while(pos != string::npos) { reverse(s.begin()+head, s.begin()+pos); head = pos + 1; pos = s.find(" ", pos+1); } reverse(s.begin()+head, s.end()); cout << s << endl; return 0; }