Codeforces--spreadsheets (Analog)

Source: Internet
Author: User
Tags integer numbers

SpreadsheetsTime limit:10000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u SubmitStatusAppoint Description:System Crawler (2015-01-06)

Description

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 number n (1?≤? N? ≤?105), the number of coordinates in the test. Then there follow n 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 than 6.

Output

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

Sample Input

Input
2r23c55bc23
Output
Bc23r23c55

The conversion between the two formats, first processing at 1 to 1000000 of the corresponding letter, for the letter converted to a number when using two points

#include <cstdio> #include <cstring> #include <algorithm>using namespace std; char str[1000010][6];  int num[1000010], low[10], Mid, high[10], char s[1000]; int serch (char *s,int i) {int l = Low[i], m, h = high[i],    K        while (l <= h) {m = (L + h)/2;        K = strcmp (s,str[m]);        if (k = = 0) return m;        if (K < 0) H = m-1;    else L = m + 1;    }}void init () {int I, j, temp; Str[1][0] = ' A ';    str[1][num[1]] = ' + ';    NUM[1] = 1;    LOW[1] = 1;        for (i = 1; I <= 1000000; i++) {temp = 1;        Num[i] = num[i-1];            for (j = num[i-1]-1; J >= 0; j--) {temp + = (str[i-1][j]-' A ' + 1);                if (temp >=) {Str[i][j] = temp-27 + ' A ';            temp = 1;                } else {Str[i][j] = temp-1 + ' A ';            temp = 0;        }} if (temp) {num[i]++;            for (j = num[i]-1; j > 0; j--) str[i][j] = str[i][j-1];            Str[i][0] = ' A ';            high[Num[i-1]] = i-1;        low[Num[i]] = i;    } str[i][Num[i]] = ' n '; } high[num[1000000]] = 1000000;}    int main () {int T, x, Y, L, I, J;    Init ();    scanf ("%d", &t);        while (t--) {scanf ("%s", s);        L = strlen (s);        for (i = 0; i < L; i++) if (s[i] >= ' 0 "&& s[i] <= ' 9 ') break;        for (; I < L; i++) if (s[i] >= ' A ' && s[i] <= ' Z ') break;            if (I < L) {//RC x = 0; y = 0;                for (i = 1; i < L; i++) {if (s[i] = = ' C ') break;            x = x * + s[i]-' 0 '; } for (i++; i < L; i++) y = y * + s[I]-' 0 ';        printf ("%s%d\n", Str[y], x);            } else {x = 0; y = 0;            for (i = 0; i < L; i++) if (s[i] >= ' 0 "&& s[i] <= ' 9 ') break;            for (j = i; J < L; j + +) x = x * + s[j]-' 0 ';            S[i] = ' + ';            y = Serch (s,i);        printf ("r%dc%d\n", X, y); }} return 0;}



Codeforces--spreadsheets (Analog)

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.