#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){ flag=0; for(int num=0;num<a[1];num++) if(!isalpha(c[num])) flag=1; printf("%d",flag) ; if(flag==0) swap(0,n-1,c); } else { flag=0; for(int num=0;num<a[1];num++) if(!isalpha(c[num])) flag=1; printf("%d",flag) ; if(flag==0) 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(!isalpha(c[num])) flag=1; if(flag==0) swap(a[i-1]+1,a[i]-1,c); flag=0; } for(num=a[k-1]+1;num<n;num++) if(!isalpha(c[num])) flag=1; if(flag==0) 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:32:21: error: 'isalpha' was not declared in this scope if(!isalpha(c[num])) ^ Main.cc:42:21: error: 'isalpha' was not declared in this scope if(!isalpha(c[num])) ^ Main.cc:49:13: error: 'num' was not declared in this scope for(num=a[i-1]+1;num<a[i];num++) ^ Main.cc:50:30: error: 'isalpha' was not declared in this scope if(!isalpha(c[num])) ^ Main.cc:56:7: error: 'num' was not declared in this scope for(num=a[k-1]+1;num<n;num++) ^ Main.cc:57:30: error: 'isalpha' was not declared in this scope if(!isalpha(c[num])) ^ 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.