http://codeforces.com/contest/1/problem/B

来源:互联网 发布:4399买号软件 编辑:程序博客网 时间:2024/04/30 14:21
B. Spreadsheetstime limit per test10 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIn 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.InputThe 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 .OutputWrite n lines, each line should contain a cell coordinates in the other numeration system.Sample test(s)Input2R23C55BC23OutputBC23R23C55

#include<iostream>#include<cstdio>using namespace std;void radix(int t){    if(t)    {        radix((t-1)/26);        putchar(65+(t-1)%26);    }}int main(){    int n,x,y;    char str[20],*p;    scanf("%d ",&n);    while(n--)    {        gets(str);        if(sscanf(str,"%*c%d%*c%d",&x,&y)==2)        {            radix(y);            printf("%d\n",x);        }        else        {            for(x=0,p=str;*p>64;p++)            {                x=x*26+*p-64;            }            printf("R%sC%d\n",p,x);        }    }    return 0;}


原创粉丝点击