View Code of Problem 114

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

Double click to view unformatted code.


Back to problem 114