Monday, June 8, 2015

UVa 483 - Word Scramble

// UVa 483 - Word Scramble

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
	string line;
	while (getline(cin, line)) {
		int ini = 0;
		while (ini < line.length()) {
			int space = line.find(' ', ini);
			string word = line.substr(ini, space - ini);
			for (int i = word.length() - 1; i >= 0; i--)
				printf("%c", word[i]);
			while (space < line.length() && line[space] == ' ') {
				printf(" ");
				space++;
			}
			ini = space;
		}
		printf("\n");
	}
	return 0;
}

No comments:

Post a Comment