Spreadsheets

很水的一道题,提醒自己要认真,做的头都快晕了。考虑26的特殊情况。
D - Spreadsheets
Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit  Status

Description

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

Input

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106.

Output

Write n lines, each line should contain a cell coordinates in the other numeration system.

Sample Input

Input
2
R23C55
BC23
Output
BC23
R23C55

 

  1 #include<cstdio>

  2 #include<cstring>

  3 #include<cstdlib>

  4 #include<cctype>

  5 using namespace std;

  6 const int maxn=100;

  7 char str[maxn];

  8 int num[maxn];

  9 void print(int n)

 10 {

 11     if(n==1)

 12         printf("A");

 13     if(n==2)

 14         printf("B");

 15     if(n==3)

 16         printf("C");

 17     if(n==4)

 18         printf("D");

 19     if(n==5)

 20         printf("E");

 21     if(n==6)

 22         printf("F");

 23     if(n==7)

 24         printf("G");

 25     if(n==8)

 26         printf("H");

 27     if(n==9)

 28         printf("I");

 29     if(n==10)

 30         printf("J");

 31     if(n==11)

 32         printf("K");

 33     if(n==12)

 34         printf("L");

 35     if(n==13)

 36         printf("M");

 37     if(n==14)

 38         printf("N");

 39     if(n==15)

 40         printf("O");

 41     if(n==16)

 42         printf("P");

 43     if(n==17)

 44         printf("Q");

 45     if(n==18)

 46         printf("R");

 47     if(n==19)

 48         printf("S");

 49     if(n==20)

 50         printf("T");

 51     if(n==21)

 52         printf("U");

 53     if(n==22)

 54         printf("V");

 55     if(n==23)

 56         printf("W");

 57     if(n==24)

 58         printf("X");

 59     if(n==25)

 60         printf("Y");

 61     if(n==26||n<=0)

 62         printf("Z");

 63 

 64 }

 65 int main()

 66 {

 67     int T;

 68     scanf("%d",&T);

 69     while(T--)

 70     {

 71         int q=0;

 72         scanf("%s",str);

 73         int len=strlen(str);

 74         int flag=1;

 75         int ok=0;

 76         int sum=0;

 77         int temp=0;

 78         int temp2=0;

 79         for(int i=0; i<len; i++)

 80         {

 81             if(flag==1&&isalpha(str[i])==0)

 82             {

 83                 flag=0;

 84                 temp2=i;

 85             }

 86             if(flag==0&&isalpha(str[i])!=0)

 87             {

 88                 ok=1;

 89                 temp=i;

 90                 break;

 91             }

 92         }

 93         if(ok)

 94         {

 95             int p=1;

 96             for(int i=len-1; i>temp; i--)

 97             {

 98                 sum+=(str[i]-'0')*p;

 99                 p*=10;

100             }

101 //            if(sum%26==0) 考虑错了

102 //            {

103 //                while(sum>0)

104 //                {

105 //                    num[q++]=sum%26-1;

106 //                    if(sum==26)

107 //                        break;

108 //                    sum/=26;

109 //                }

110 //            }

111 //            else

112 

113                 while(sum>0)

114                 {

115                     if(sum%26==0)        

116                     {

117                         num[q++]=26;

118                         sum=sum/26-1;

119                     }

120                     else{

121                     num[q++]=sum%26;

122                     sum/=26;

123                 }

124             }

125             for(int i=q-1; i>=0; i--)

126             {

127                 // printf("%d ",num[i]);

128                 print(num[i]);

129             }

130             for(int i=1; i<temp; i++)

131                 printf("%c",str[i]);

132         }

133         else

134         {

135             printf("R");

136             for(int i=temp2; i<len; i++)

137                 printf("%c",str[i]);

138             printf("C");

139             int p=1;

140             for(int i=temp2-1; i>=0; i--)

141             {

142                 sum+=(str[i]-'A'+1)*p;

143                 p*=26;

144             }

145             printf("%d",sum);

146         }

147         printf("\n");

148     }

149 }

 

 

你可能感兴趣的:(Spread)