You are viewing a single comment's thread. Return to all comments →
I am using the same logic but it is working only for test case 0 can some one help me find out what is wrong long int t; int l,m,i,j;
scanf("%ld ",&t); char ch[101],c; while(t>=1) { scanf("%s",ch); l=strlen(ch)-1; i=l+1; do { i--; if(i==0) break; }while(ch[i]<=ch[i-1]); if(i!=0) { m=i; while(m<=l) { if(ch[m]<ch[i-1]) break; m++; } m--; c=ch[m]; ch[m]=ch[i-1]; ch[i-1]=c; for(m=l;m>=i+1;m--) { for(j=i;j<m;j++) { if(ch[j]>ch[j+1]) { c=ch[j]; ch[j]=ch[j+1]; ch[j+1]=c; } } } for(i=0;i<=l;i++) printf("%c",ch[i]); } else printf("no answer"); printf("\n"); t--; }
Seems like cookies are disabled on this browser, please enable them to open this website
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
I am using the same logic but it is working only for test case 0 can some one help me find out what is wrong long int t; int l,m,i,j;