View Code of Problem 114

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	while (getline(cin, a)){
		int k = 0;
		for (int i = 0; i < a.length(); i++) {
			if (isalpha(a[i])) {
				k++;
			}
			else {
				if (k != 0) {
					for (int j = i - 1; j >= i - k; j--) {
						cout << a[j];
					}
					k = 0;
					cout << a[i];
				}
				else
					cout << a[i];
			}

		}
		if (k != 0) {
		int len = a.size();	
		for (int j = len-1; j >=len - k; j--) {
			cout << a[j];
		}
		}
		cout << endl;
	}
	
}

Double click to view unformatted code.


Back to problem 114