Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <list>
- #include <vector>
- using namespace std;
- string reverse(string str)
- {
- string revStr = "";
- for (int i = str.length() - 1; i >= 0; i--)
- {
- revStr += str[i];
- }
- return revStr;
- }
- int main()
- {
- string str;
- getline(cin, str);
- string word;
- string result;
- for (int i = str.length() - 1; i >= 0; i--)
- {
- if (str[i] == ' ')
- {
- if (word.length() == 0)
- {
- continue;
- }
- result += reverse(word) + " ";
- word = "";
- }
- else
- {
- word += str[i];
- }
- }
- cout << result + reverse(word) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement