Tien-Zhao's blog

By Tien-Zhao, history, 8 years ago, In English
After I changed different locally-feasible ways to submit, it always stuck in the same place - test 6, word 61.
I was given the comment "wrong answer 61st words differ - expected: 'R1C48', found: 'HX3762'", from which I can infer that the input should be AV1. (I couldn't see it because it was hidden in the ellipsis"..." ) However, when I typed AV1 in the local window, it started working perfectly.
I'm a newbie in C programming and I've no idea at all on the mistake above. Hopefully someone can help me, appreciate!

[problem:1B]
[15960294](http://codeforces.com/contest/1/submission/15960294)

(here is my code with more notes; the picture is captured when i run it on my pc.)

include <stdio.h>

int main() { //Get the 1st input for the times to loop. int i=1; int j; char input[14]; scanf("%d",&j);

for(i;i<=j;i++)
{
    scanf("%s",&input);  //Get the input String.
    int b=1,c=1;
    do
    {
        b++;
        c++;
        if(input[c-1]<58 && input[c]==67) //67=='C'.
        {
            b=15;   //Recognize the "RxxCyy" ones, which will end the 'for loop' and go to 'b==15' branch.
        }
    }
    while(b<14);

    int rn=0, cn=0, in=0;

    if(b==15) //Deal with ‘RxxCyy’ ones.
    {
        int a;
        for(a=1; a<c; a++)  //Get 'xx' and name it as 'rn'.
        {
            in=input[a]-48;
            rn=rn*10+in;
        }
        for(a=c+1; input[a]>47 && input[a]<58 ; a++)   //Get 'yy' and name it as 'cn'.
        {
            in=input[a]-48;
            cn=cn*10+in;
        }
        int o=4;
        char co[5]; //Start a string "co".
        int q;
        for(q=0;q<=o;q++)  //Fill the string "co" with '@'s.
            co[q]='@';
        q--;
        for(o;cn>0;o--)   //Fill ‘co' from right to left with proper letters.
        {
            co[o]=(cn-1)%26+65;
            cn=(cn-(cn-1)%26-1)/26;
        }
        int r,s;
        for(r=0;co[r]=='@';q--)  //Move the letters to the left.
        {
            for(s=0;s<q;s++)
            {
                co[s]=co[s+1];
            }
            co[q]=0;
        }
        printf("%s%d\n",co,rn);  //Print the answer.
    }

    else      //Deal with the 'CCrrr' ones.
    {
        int a, r, c;
        for(a=1;input[a]>47 && input[a]<91 ; a++)  //Get the length of whole string.
            a;
        for(c=1; input[c]>64 && input[c]<91; c++)  //Get the length of "CC".
            c;

        int ro=0, co=0;
        for(r=c; r<a; r++)  //Convert 'rrr' to integer.
            ro=10*ro+input[r]-48;
        a=c;
        for(c=0; c<a; c++)  //Convert 'CC' to integer.
            co=26*co+input[c]-64;
        printf("R%dC%d\n",ro,co);  //Print the answer.
    }
}
return(0);

}

  • Vote: I like it
  • -5
  • Vote: I do not like it