View Code of Problem 114

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string str;
	while (getline(cin, str)) {
		int len = str.size();
		for (int i = 0,p; i < len;i++) {
			string s;
			while (i < len && !isalpha(str[i]))i++;
			if (i == len) break;
			p = i;
			s += str[i];
			for (i++; i < len&&isalpha(str[i]); i++) s += str[i];
			reverse(s.begin(), s.end());
			str.replace(p, i - p, s);
		}
		cout << str << endl;
	}
}

Double click to view unformatted code.


Back to problem 114