You are viewing a single comment's thread. Return to all comments →
scanf("%d",&t); for(int g=0;g<t;g++) { // char s[100],min,max,temp[100],ss[100]; char* s=(char*)malloc(sizeof(char)*100); memset(s,0,100); char* temp=(char*)malloc(sizeof(char)*100); memset(temp,0,100); char* ss=(char*)malloc(sizeof(char)*100); memset(ss,0,100); char max; scanf("%s",s); strcpy(ss,s); int len=0,cons; while(s[len]!='\0') { len++; } int c=0; for(int i=len-1;i>0;i--) { cons=i; if(s[i]<=s[i-1]) { temp[c]=s[i]; c++; } else { temp[c]=s[i]; c++; break; } } if(c==0) c++; for(int k=0;k<c;k++) { if(s[cons-1]<temp[k]) { max=s[cons-1]; s[cons-1]=temp[k]; temp[k]=max; break; } } for(int j=0;j<c;j++) { s[cons+j]=temp[j]; } if(strcmp(ss,s)) printf("%s\n",s); else printf("no answer\n"); free(s); free(ss); free(temp); } so one please help me my testcase1 and 2 showing wrong
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →