View Code of Problem 114

#include<stdio.h>
#include<string.h>
int main(){
	char input[100];
	int len, i, j, k, temp;
	while(gets(input)) {
		temp = k = 0;
		len = strlen(input);
		char output[len];
		for(i=0; i<len; i++) {
			if(input[i] == ' ') {
				for(j=i-1; j>=temp; j--) {
					output[k] = input[j];
					k++;
				}
				output[k] = input[i];
				k++;
				temp = i+1;
			}
			else if(input[i+1] == '\0') {
				for(j=i; j>=temp; j--) {
					output[k] = input[j];
					k++;
				}
			}
		}
		for(i=0; i<len; i++) {
			printf("%c", output[i]);
		}
		printf("\n");
	}
}

Double click to view unformatted code.


Back to problem 114