Codeforce 1B Spreadsheets

题目链接:点击打开链接

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
2
R23C55
BC23
Output
BC23
R23C55

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值