zl程序教程

您现在的位置是:首页 >  其他

当前栏目

CodeForces 1B. Spreadsheets(模拟)

模拟 Codeforces
2023-09-27 14:25:13 时间

题目链接:http://codeforces.com/problemset/problem/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


题意:

对换两种不同的表示方法表示行列!

代码例如以下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 117;
typedef __int64 LL;
int is_letter(char c)
{
    if(c >= 'A' && c <= 'Z')
        return 1;
    return 0;
}

int is_num(char c)
{
    if(c >='0' && c <='9')
        return 1;
    return 0;
}

int main()
{
    LL t;
    char s[maxn];
    scanf("%I64d",&t);
    getchar();
    while(t--)
    {
        gets(s);
        int len = strlen(s);
        int k = 0;
        for(int i = 0; i < len; i++)
        {
            if(is_letter(s[i]) && is_num(s[i+1]))
            {
                k++;
            }
        }
        if(k == 2)//R23C55形式
        {
            LL i, j;
            LL t1 = 0, t2 = 0;
            for(i = 1; ; i++)
            {
                if(is_num(s[i]))
                    t1 = t1*10+s[i]-'0';
                else
                    break;
            }
            for(j = i+1; j < len; j++)
            {
                if(is_num(s[j]))
                    t2 = t2*10+s[j]-'0';
                else
                    break;
            }
            //printf("t1::%I64d t2::%I64d\n",t1,t2);
            char a[maxn];
            i = 0;
            while(t2)
            {
                LL tt = t2%26;
                a[i++] = tt+'A'-1;
                t2/=26;
                if(tt == 0)//注意
                {
                    t2--;
                    a[i-1] = 'Z';
                }

            }
            for(j = i-1; j >= 0; j--)
            {
                printf("%c",a[j]);
            }
            printf("%I64d\n",t1);
        }
        else//BC23形式
        {
            LL i, j;
            LL t3 = 0, t4 = 0;
            for(i = 0; ; i++)
            {
                if(is_num(s[i]))
                    break;
                t3 = t3*26+(s[i]-'A'+1);
            }
            for(j = i; j < len; j++)
            {
                t4 = t4*10+s[j]-'0';
            }
            printf("R%I64dC%I64d\n",t4,t3);
        }
    }
    return 0;
}

/*
99
R23C55
BC23
R26C78
BZ26
*/