#include<stdio.h> #include<string.h> int swap(int m,int n,char s[]) { int i; char temp; for(i=0;i<(n-m+1)/2;i++) { temp=s[i+m]; s[i+m]=s[n-i]; s[n-i]=temp; } return 0; } int main() {int i,k,a[1000],n,flag; char c[1000],s,temp; while(gets(c)!=NULL) {n=strlen(c); memset(a,0,sizeof(a)); k=1;flag=0; a[0]=0; for(i=1;i<n;i++) {if(c[i]==' ') { a[k++]=i; flag=1; } } if(!flag) swap(0,n-1,c); else { flag=0; for(int num=a[1]-1;num<(a[2]);num++) if('a'<=c[num]<='z'||'A'<=c[num]<='Z') flag=1; if(flag=1) swap(0,a[1]-1,c); flag=0; for(i=2;i<k;i++){ for(num=a[i-1]+1;num<(a[i]);num++) if('a'<=c[num]<='z'||'A'<=c[num]<='Z') flag=1; if(flag=1) swap(a[i-1]+1,a[i]-1,c); flag=0; } for(num=a[k-1]+1;num<(n);num++) if('a'<=c[num]<='z'||'A'<=c[num]<='Z') flag=1; if(flag=1) swap(a[k-1]+1,n-1,c); } printf("%s\n",c); } return 0; } /* Main.cc: In function 'int main()': Main.cc:18:7: warning: 'char* gets(char*)' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations] while(gets(c)!=NULL) ^ Main.cc:18:13: warning: 'char* gets(char*)' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations] while(gets(c)!=NULL) ^ Main.cc:35:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses] if('a'<=c[num]<='z'||'A'<=c[num]<='Z') ^ Main.cc:35:29: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses] if('a'<=c[num]<='z'||'A'<=c[num]<='Z') ^ Main.cc:37:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if(flag=1) ^ Main.cc:41:8: error: 'num' was not declared in this scope for(num=a[i-1]+1;num<(a[i]);num++) ^ Main.cc:44:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if(flag=1) ^ Main.cc:48:5: error: 'num' was not declared in this scope for(num=a[k-1]+1;num<(n);num++) ^ Main.cc:51:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if(flag=1) ^ Main.cc:17:14: warning: unused variable 's' [-Wunused-variable] char c[1000],s,temp; ^ Main.cc:17:16: warning: unused variable 'temp' [-Wunused-variable] char c[1000],s,temp; ^ */ |
Double click to view unformatted code.