Codeforces 1 B (26 binary processing of strings)

Source: Internet
Author: User
Tags integer numbers

B. Spreadsheets
Http://codeforces.com/problemset/problem/1/B

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns are used. The first column has A number A, the Second-number B, etc. till column, which is marked by Z. Then there was Two-letter Numbers:column have number AA, 28-ab, column is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows is marked by an integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 are the name for the cell, which is in column, row 23.

Sometimes another numeration system is used:rxcy, where X and Y are integer numbers, showing the column and the row Numbe RS respectfully. For instance, r23c55 are the cell from the previous example.

Your task is to write a program this 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?≤? N? ≤?105), the number of coordinates in the test. Then there follown lines, each of the them contains coordinates. All the coordinates is correct, there is no cells with the column and/or the row numbers larger than6 .

Output

Write n lines, each of the line should contain a cells coordinates in the other numeration system.

Sample Test (s)Input
2r23c55bc23
Output
bc23r23c55 title meaning: Simple is 10 binary and 26 binary conversion, give Rxcy conversion long yx, where Y is 26, simulation problems, not difficult but a variety of traps, look at their own character, I do not know how many times wa .... , you have to pay attention to the kind of conversion, is RXCY-->XY? or Xy->rxcyac code:
/** * @xiaoran * Test instructions meaning, 26 binary conversion */#include <iostream> #include <cstdio> #include <map> #include < cstring> #include <string> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <cstdlib> #include <cctype> #include <cmath> #define LL long longusing namespace    Std;void Inttosta (char *s) {int sr,sc,len;    sr=sc=0;    Len=strlen (s);        for (int i=0;i<len;i++) {if (Isalpha (S[i])) {//Is the letter sc=sc*26+ (s[i]-' A ' + 1);        } if (IsDigit (S[i])) {//is a digital sr=sr*10+ (s[i]-' 0 '); }} printf ("r%dc%d\n", SR,SC);}    void Statoint (char *s) {int sr,sc,len;    sr=sc=0;    Len=strlen (s);    SSCANF (S, "r%dc%d", &AMP;SR,&AMP;SC);    printf ("%d%d\n", SR,SC);    int res=sc,mes,k=0; RES=SC/26;    mes=sc%26;    Char ss[58];            while (res) {if (res%26==0) {ss[k++]= ' A ' +res%26-1+26;            res/=26;        Res-=1;     } else{ss[k++]= ' A ' +res%26-1;   printf ("%c", ' A ' +res%26);        res/=26;    }}//ss[k]= ' A ' +res-1;    for (int i=k-1;i>=0;i--) printf ("%c", Ss[i]);    printf ("%d\n", SR); printf ("r%dc%d\n", SR,SC);}    int main () {int n;    Char s[100];    scanf ("%d", &n);        while (n--) {scanf ("%s", s);        int ok1=0,ok2=0;        ok1=s[0]== ' R ' &&isdigit (s[1]);        for (int I=0;i<strlen (s) -1;i++) {if (s[i]== ' C ' &&isdigit (s[i+1])) ok2=1;        }//OK1&AMP;OK2 determines which function to select if (OK1&AMP;&AMP;OK2) statoint (s);    else Inttosta (s); }return 0;}


Codeforces 1 B (26 binary processing of strings)

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.