Codeforce 1B Spreadsheets

来源:互联网 发布:战地1优化真的好 编辑:程序博客网 时间:2024/05/18 20:50

题目链接:点击打开链接

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 than106 .

Output

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

Sample Input

Input
2R23C55BC23
Output
BC23R23C55

ps:进制的转换的变形,特殊处理一下,10->26,,,26->10,

处理看注释:

#include <iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;int  a[20006];char word[28];char s[20006];void intit(){    word[1]='A';    for(int i=2;i<=26;i++)    {        word[i]=word[i-1]+1;    }}int main(){    int n;    intit();    while(cin>>n)    {        while(n--)        {            cin>>s;            int len=strlen(s);            int flag=0;            //int f=0;            int p;            for(int i=0; i<len; i++)            {                if(s[i]>='0'&&s[i]<='9')                {                    p=i;                    break;                }            }            for(int i=p; i<len; i++)            {                if(s[i]>='A'&&s[i]<='Z')                {                    flag=1;                    break;                }            }            if(flag)            {                long long R,C;                long long d=1;                C=0;                int pos;                for(int i=len-1; i>=0; i--)                {                    if(s[i]=='C')                    {                        pos=i;                        break;                    }                    C=C+d*(s[i]-'0');                    d=d*10;                }               // cout<<C<<endl;                R=0;                d=1;                for(int i=pos-1; i>=0; i--)                {                    if(s[i]=='R')                    {                        break;                    }                    R=R+d*(s[i]-'0');                    d=d*10;                }                //cout<<R<<endl;                int top=0;                int c;                while(C)                {                    c=C%26;                    if(c==0)///单独处理的地方,在这卡了                    {                        a[top++]=26;                        C=C/26-1;                    }                    else                    {                        a[top++]=C%26;                        C=C/26;                    }                }               for(int i=top-1;i>=0;i--)                {                    printf("%c",word[a[i]]);                    //if(ttt==1&&i==0)break;                }                printf("%lld\n",R);                //cout<<"**\n";            }            else            {                // int top=0;                int pos;                for(int i=0; i<len; i++)                {                    if(s[i]>='0'&&s[i]<='9')                    {                        pos=i;                        break;                    }                    //b[top++]=s[i];                }                long long C;                C=0;                /*for(int i=0; i<pos; i++)                {                    //C=C+(s[i]-'A'+1)*pow(26,k);                    C=C*26+s[i]-'A'+1;                }*/                for(int k=0,i=pos-1;i>=0;i--,k++)                {                   // if(k==0)C=C+(s[i]-'A'+1)                     C=C+(s[i]-'A'+1)*(int)pow(26.0,k);///注意:pow的用法,pow(double x,double y),x为浮点数                }                printf("R");                for(int i=pos; i<len; i++)                {                    printf("%c",s[i]);                }                printf("C");                printf("%lld\n",C);            }        }    }    return 0;}


0 0
原创粉丝点击