View Code of Problem 114

#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
	char s1[100];

	while(gets(s1)!=NULL){
	
		int len=strlen(s1);
		int i; 
		int n;
		for(int i=0;i<len;i++){
			n=1;
			if((s1[i]>'A'&&s1[i]<'Z')||(s1[i]<'z'&&s1[i]>'a')){
				for(int j=i+1;j<len;j++){
					if((s1[j]>'A'&&s1[j]<'Z')||(s1[j]<'z'&&s1[j]>'a')){
						n++;//n代表这个单词有几位 
					}else{
						break;
					}
				}
				//现在将这个单词逆序输出
				for(int k=i+n-1;k>=i;k--){
					printf("%c",s1[k]);
				} 
				i=n+i-1;	
			
			}else{
				printf("%c",s1[i]);
			}
		
		}//for
		printf("\n"); 
		
	} 
	
	return 0;
}

Double click to view unformatted code.


Back to problem 114