cf --1 --B

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.

Sample test(s)
input
2
R23C55
BC23
output
BC23
R23C55
 
         
题目意思是  有两种exl表格位置表示形式 ,一种是R..C..形式,另一种是字母加数字形式,给你一种形式,将其转换成另一种形式
下面给出ac代码,调了好久==||
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int myabs(int a,int b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
int f(char s[])
{
    int ans=0;
    for(int i=0; i<strlen(s); i++)
    {
        ans=(s[i]-'0')+ans*10;
    }
    return ans;
}
int altonum(char s[])
{
    int ans=0;
    for(int i=0; i<strlen(s); i++)
    {
        ans=ans*26+(int)(s[i]-'A'+1);
    }

    return ans;

}
int main()
{
    char ans1[50],ans2[50];
    char str[100];
    int ci,ri;
    int n,ans;
    int k,g;
    int num[100];
    cin>>n;
    while(n--)
    {
        cin>>str;
        int len=strlen(str);
        ci=-1;
        ri=-1;
        for(int i=0; i<len; i++)
        {
            if(str[i]=='R')
                ri=i;
            if(str[i]=='C')
                ci=i;
        }
        if(myabs(ci,ri)>1&&str[ci-1]-'0'>=0&&str[ci-1]-'0'<=9&&ci!=-1&&ri!=-1)///R C 之间必须是数字,
        {
            //cout<<1<<endl;
            k=0,g=0;
            int j;
            for(int i=0; i<len; i++)
            {
                if(str[i]=='R')
                {
                    for(j=i+1; j<len; j++)
                    {
                        if(str[j]=='C')
                        {
                            //  cout<<"j"<<j<<endl;
                            ans2[k]='\0';
                            break;
                        }
                        ans2[k++]=str[j];
                    }
                    for(j=j+1; j<len; j++)
                    {
                        ans1[g++]=str[j];
                    }
                    ans1[g]='\0';
                    break;
                }

            }
            ans=f(ans1);
            k=0;
            while(ans)
            {
                num[k++]=ans%26;
                int t=ans;
                ans=ans/26;
                if(t%26==0)
            ans--;
            }
            for(int i=k-1; i>=0; i--)
            {
                if(num[i]==0)
                    cout<<"Z";
                else
                cout<<char(num[i]-1+'A');
            }
            cout<<ans2<<endl;
        }
        else
        {
            k=0,g=0;
            for(int i=0; i<len; i++)
            {
                if(isalpha(str[i]))
                    ans2[k++]=str[i];
                else if(str[i]-'0'<=9&&str[i]-'0'>=0)
                    ans1[g++]=str[i];
            }
            ans1[g]='\0';
            ans2[k]='\0';
            cout<<"R"<<ans1<<"C";
            ans=altonum(ans2);
            cout<<ans<<endl;
        }

    }
    return 0;
}


你可能感兴趣的:(cf --1 --B)