|
|
back to boardCommon Boardwhere're my bugs? help me please=>problem 1123 this is my program => #include <stdio.h> #include <string.h> int main() { int state,pos,i,n,len,reach=0; char str[2005],a; scanf("%s",str); len=strlen(str); n=len/2; for(i=0,state=0;i<n;i++) { if(str[i]!=str[len-i-1]) {if(state==1) { str[pos]=a; state=0; reach=1; } a=str[i]; pos=len-i-1; state=1; } } if(!reach) if(str[pos]>str[len-pos-1]) { str[len-pos-1]++; str[pos]=str [len-pos-1]; } else str[pos]=str[len-pos-1]; else { if(str[len-pos-1]>str[pos]) { str[pos]=str[len-pos-1]; } else { str[len-pos-1]++; str[pos]=str[len-pos-1]; } } printf("%s",str); return 0; } Looks like you do not handle if 9s appear in the middle. You should increase (+1) the digit before the 9s then change the 9s with 0s. Re: Looks like you do not handle if 9s appear in the middle. oh Thank you very much |
|
|