B. Spreadsheets

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    string a;
    string b,c;
    int i,j;
    int num1;
    int num0;
    int nu;
    scanf("%d",&nu);
    int flag=0;
    for(int ii=0; ii<nu; ii++)
    {
        int step=0;
        int n=1;
        flag=0;
        num0=num1=0;
        cin>>a;
        int ii=0;
        while(a[ii]>='A'&&a[ii]<='Z') ++ii;
        for(int g=ii;g<a.size();g++)
         if(a[g]=='C')
          {
              flag=1;break;
          }
        if(flag==0)
        {
            int st=0;
            while(a[st]>='A'&&a[st]<='Z') ++st;
            for(i=st-1; i>=0; i--)
            {
                num0+=(a[i]-'A'+1)*n;
                n*=26;
            }
            for(i=st; i<a.size(); i++)
            {
                num1=num1*10+a[i]-'0';
            }
            printf("R%dC%d\n",num1,num0);
        }
        else
        {
            for(i=1; a[i]!='C'; i++)
            {
                num0=num0*10+a[i]-'0';
            }
            for(j=i+1; j<a.size(); j++)
            {
                num1=num1*10+a[j]-'0';
            }
         //   printf("%d %d\n",num0,num1);
            if(num1<=26)//有一个字母
            {
                printf("%c%d\n",num1+'A'-1,num0);
            }
            else if(num1<=702)//有两个字母
            {
                int aa=num1%26;
                if(aa==0)
                {
                    aa=26;
                }
                num1-=aa;
                printf("%c%c%d\n",num1/26+'A'-1,aa+'A'-1,num0);
            }
            else if(num1<=18278)//有三个字母
            {
                //1 26 676 17576 456976 11881376
                int aa=num1%26;
                if(aa==0)
                    aa=26;
                num1=num1-aa;
                int bb=num1%676;
                if(bb==0)
                    bb=676;
                num1=(num1-bb)/676;
                bb/=26;
              //  printf("aa=%d bb=%c num1=%d\n",aa,bb+'A'-1,num1);
                printf("%c%c%c%d\n",num1+'A'-1,bb+'A'-1,aa+'A'-1,num0);
            }
            else if(num1<=475254)//四位字母
            {
                int aa=num1%26;
                if(aa==0)
                    aa=26;
                num1=num1-aa;
                int bb=num1%676;
                if(bb==0)
                    bb=676;
                num1=num1-bb;
                bb/=26;
                int cc=num1%17576;
                if(cc==0)
                  cc=17576;
                num1-=cc;
                cc/=676;
                num1/=17576;
                printf("%c%c%c%c%d\n",num1+'A'-1,cc+'A'-1,bb+'A'-1,aa+'A'-1,num0);
            }
            else
            {
                int aa=num1%26;
                if(aa==0)
                    aa=26;
                num1=num1-aa;
                int bb=num1%676;
                if(bb==0)
                    bb=676;
                num1=num1-bb;
                bb/=26;
                int cc=num1%17576;
                if(cc==0)
                  cc=17576;
                num1-=cc;
                cc/=676;
                int dd=num1%456976;
                if(dd==0)
                  dd=456976;
                num1-=dd;
                  dd/=17576;
                num1/= 456976;
               // printf("%d %d %d %d %d %d\n",num1,dd,cc,bb,aa,num0);
               printf("%c%c%c%c%c%d\n",num1+'A'-1,dd+'A'-1,cc+'A'-1,bb+'A'-1,aa+'A'-1,num0);
            }
        }
    }
    return 0;
}
//1 26 676 17576 456976 11881376
/*
t1=26;
t2=728;
t3=19682;
t4=531440;
t5=14348906;
1000
R621C406
ABD815
R3C24
R634C162
R695C621
R875C898
AHG626
AFE664
R95C969
R21C933
R629C648
R253C417
WQ20
AGA989
XO484
R912C396
R292C168
PI999
TR254
PH609
R207C905
R762C995
LL946
R292C805
R174C206
NY237
R345C125
R657C212




OP621
R815C732
X3
FF634
WW695
AHN875//
R626C891
R664C837
AKG95//
AIW21//
XX629
PA253
R20C615
R989C859
R484C639
OF912
FL292
R999C425
R254C538
R609C424
AHU207//
ALG762//
R946C324
ADY292
GX174
R237C389
DU345
HD657
R185C831
R81C54
R448C215...
*/


你可能感兴趣的:(B. Spreadsheets)