Codeforces Beta Round #1 B. Spreadsheets

来源:互联网 发布:风力发电现状 知乎 编辑:程序博客网 时间:2024/05/23 02:04
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 numbern (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follown 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.

Examples
Input
2R23C55BC23
Output
BC23R23C55
题意:将两种表示行列的方法相互转化,不能出现0
这题不难但是容易出错,例如52转化为字母应输出AZ,注意下就好,从字母转成行就不用讲了,= =,将数字转换成字母思路就是先将数字的转化为26进制数,然后从最低位向最高位扫,如果当前这一位小于等于0就将这一位加上26,前一位减一。
#include<iostream>#include<algorithm>#include<cmath>#include<cstdio>#include<queue>#include<cstring>#include<string>#include<map>#include<set>using namespace std;#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define sf scanf#define pf printf#define mem(i,a) memset(i,a,sizeof i)#define pi acos(-1.0)int m;char g[100];int a[10],b[10];int main(){    sf("%d",&m);    while(m--)    {        int r=0,c=0;        int tag;        sf("%s",g);        int k=0,u=0;        for(int i=1;i<strlen(g);i++)//判断要进行哪一种转换        {            if(!u)            {                if(g[i]<'A')                    u=1,k++;            }            else            {                if(g[i]>'9')                    u=0,k++;            }        }        tag=(k==1)?1:0;        if(tag)        {            int i;            for(i=0;g[i]>'9';i++)                r=r*26+(g[i]-'A'+1);            for(;i<strlen(g);i++)                c=c*10+g[i]-'0';            pf("R%dC%d\n",c,r);//这里注意不能搞反了        }        else        {            int i,p=0;            for(i=1;g[i]<='9';i++)                r=r*10+g[i]-'0';            for(i+=1;i<strlen(g);i++)                c=c*10+g[i]-'0';//将数据提取出来            while(c)                b[p++]=c%26,c/=26;//转换成26进制数            for(int i=0;i<p-1;i++)//从低位到高位进行扫描            {                if(b[i]<1)                {                    b[i]+=26;                    --b[i+1];                    a[i+1]=b[i+1];                }                a[i]=b[i];            }            a[p-1]=b[p-1];            for(int i=p-1;i>=0;i--)                if(a[i])                    pf("%c",a[i]-1+'A');            pf("%d\n",r);        }    }    return 0;}