1B. Spreadsheets【进制转换】

来源:互联网 发布:什么命令linux死机 编辑:程序博客网 时间:2024/06/05 01:19

B. Spreadsheets
time limit per test
10 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Examples
input
2R23C55BC23
output
BC23R23C55


进制转换是关键,一个简单的进制转换卡了一上午,真心感觉弱爆了.....


/*http://blog.csdn.net/liuke19950717*/#include<cstdio>#include<cmath>#include<cstring>#include<stack>using namespace std;typedef long long ll;const int maxn=1005;bool judge(char s[])//判断是否是声明行和列的方式{    int len=strlen(s);    if(len<=2)    {        return 0;//没有声明行和列    }    int kase=0;    for(int i=0;i<len;++i)    {        if(s[i]>='A'&&s[i]<='Z'&&kase)        {            return 1;        }        if(s[i]>='0'&&s[i]<='9')        {            kase=1;        }    }    return 0;}void slove(char s[]){int len=strlen(s);if(judge(s))//声明了行和列{int x=0,y=0,i=1;while(s[i]!='C'){    y=y*10+s[i]-'0';++i;}++i;while(i<len){x=x*10+s[i]-'0';++i;}stack<char> ans;while(x)        {            int tp=(x-1)%26+'A';            ans.push(tp);            x=(x-1)/26;        }while(!ans.empty()){printf("%c",ans.top());ans.pop();}printf("%d",y);}else{int x=0,y=0,i=0;while(s[i]>='A'&&s[i]<='Z')        {            y=y*26+s[i]-'A'+1;            ++i;        }        while(i<len)        {            x=x*10+s[i]-'0';            ++i;        }        printf("R%dC%d",x,y);}printf("\n");}int main(){int t;scanf("%d",&t);while(t--){char s[maxn]={0};scanf("%s",s);slove(s);}return 0;}



0 0
原创粉丝点击