B. Spreadsheets

Source: Internet
Author: User
Tags integer numbers
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 digit ≤ DigitNLimit ≤ limit 105 ),
The number of coordinates in the test. Then there followNLines, 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

WriteNLines, each line shoshould contain a cell coordinates in the other numeration system.

Sample test (s) Input
2R23C55BC23
Output
BC23R23C55

Description: This is to convert two types of representation, mainly for string processing.

#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;char line[1024], t[1024], *p;int r, c;void printcol(int c) {        if(!c) {return;}        printcol((c - 1)/26);        putchar(((c - 1)% 26) + 'A');}int main(){int n,i;scanf("%d",&n);for(i=0;i<n;i++){scanf("%s", line);        if(sscanf(line,"R%dC%d", &r, &c) == 2) {            printcol(c);            printf("%d\n", r);        } else {           sscanf(line, "%[A-Z]%d", t, &r);           for(p = t, c = 0; *p; p++) {c = c * 26, c += *p - 'A' + 1;}printf("R%dC%d\n", r, c);         }}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.