View Code of Problem 114

#include <stdio.h>
#include <string.h>
int main(){
	char a[1000]={'\0'};
	while(gets(a)!=NULL){
		int i,j,k;
		char swap;
		for(i=0;i<strlen(a);){
			if(a[i]==' '){
				i++;
			}
			else{
				for(j=i;j<strlen(a)&&a[j]!=' ';j++);
				j--;
				for(k=1;k<=(j-i+1)/2;k++){
					swap=a[i+k-1];
					a[i+k-1]=a[j-k+1];
					a[j-k+1]=swap;
				}
				i=j+1;
			}
		}
		puts(a);
	}
}

Double click to view unformatted code.


Back to problem 114