View Code of Problem 114

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
	string s;
	while (getline(cin, s)){
		int k = 0;
		for (int i = 0; i < s.length(); i++) {
			if (isalpha(s[i])) {
				k++;
			}
			else {
				if (k != 0) {
					for (int j = i - 1; j >= i - k; j--) {
						cout << s[j];
					}
					k = 0;
					cout << s[i];
				}
				else
					cout << s[i];
			}

		}
		for (int j = s.length() - 1; j >= s.length() - k; j--) {
			cout << s[j];
		}
		cout << endl;
	}
	
}

Double click to view unformatted code.


Back to problem 114