#include<iostream> #include<vector> #include<algorithm> #include<string> #include<climits> #include<cmath> #include<map> #include<set> using namespace std; int main() { string str; while (getline(cin, str)) { int len = 0; int begin = 0; string res; for (int i = 0; i < str.size(); i++) { if (isalpha(str[i])) len++; else { if (len > 0) { string temp = str.substr(begin, len); reverse(temp.begin(), temp.end()); res += temp; begin = i + 1; len = 0; } else begin = i + 1; res += str[i]; } } if (len > 0) { string temp = str.substr(begin, len); reverse(temp.begin(), temp.end()); res += temp; } cout << res << endl; } } |
Double click to view unformatted code.