View Code of Problem 114

#include <bits/stdc++.h>
using namespace std;
int main() {
	string str;
	while (getline(cin, str)) {
		int flag = 0;
		string num;
		for (int i = 0; i < str.length(); i++) {
			if (str[i] >= 'a'&&str[i] < 'z' || str[i] >= 'A'&&str[i] < 'Z') {
				num += str[i];
				flag = 1;
			}
			else if (str[i] == ' '&&flag) {
				reverse(num.begin(), num.end());
				cout << num << " ";
				num = "";
				flag = 0;
			}
			else if (str[i] == ' '&&flag == 0)
				cout << " ";
			if (i == str.length() - 1 && flag) {
				reverse(num.begin(), num.end());
				cout << num;
			}
		}
		cout << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 114