CF # 1 B. Spreadsheets

Source: Internet
Author: User
Tags integer numbers strlen time limit
Http://codeforces.com/contest/1/problem/B B. Spreadsheets time limit per test seconds memory limit per test megabyte s input standard input output standard output

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) and 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 106. Output

Write n lines, each of the line should contain a cells coordinates in the other numeration system. Sample Test (s) input

2
r23c55
BC23
Output
BC23
R23c55

There are two representations of a grid, one is the r***c*** form, the other is the letter + number form, and two conversion relationships can be seen in the sample;
#include <iostream> #include <stdio.h> #include <string.h> using namespace std;
    int myabs (int a,int b) {if (a>b) return a-B;
else return b-a;
    } int F (char s[]) {int ans=0;
    for (int i=0; I<strlen (s); i++) {ans= (s[i]-' 0 ') +ans*10;
} return ans;
    } int Altonum (char s[]) {int ans=0;
    for (int i=0; I<strlen (s); i++) {ans=ans*26+ (int) (s[i]-' A ' + 1);

} return ans;
    } int main () {char ans1[50],ans2[50];
    Char str[100];
    int Ci,ri;
    int N,ans;
    int k,g;
    int num[100];
    cin>>n;
        while (n--) {cin>>str;
        int Len=strlen (str);
        Ci=-1;
        Ri=-1;
            for (int i=0; i<len; i++) {if (str[i]== ' R ') ri=i;
        if (str[i]== ' C ') ci=i; } if (Myabs (ci,ri) >1&&str[ci-1]-' 0 ' >=0&&str[ci-1]-' 0 ' <=9&&ci!=-1&&ri!=- 1)///r C must be a number, {//cout<<1<<endl;
            k=0,g=0;
            Int J;  for (int i=0, i<len; i++) {if (str[i]== ' R ') {for (j=i+1; j<len; J + +) {if (str[j]== ' C ') {/
                            /cout<< "J" <<j<<endl;
                            ans2[k]= ' + ';
                        Break
                    } Ans2[k++]=str[j];
                    } for (j=j+1; j<len; J + +) {Ans1[g++]=str[j];
                    } ans1[g]= ' + ';
                Break
            }} ans=f (ANS1);
            k=0;
                while (ans) {num[k++]=ans%26;
                int T=ans;
                ANS=ANS/26;
           if (t%26==0) ans--; } for (int i=k-1; i>=0; i--) {if (num[i]==0) cout<< "Z"
                ;
            else Cout<<char (num[i]-1+ ' A ');
        } cout<<ans2<<endl;
            } else {k=0,g=0;
                for (int i=0; i<len; i++) {if (Isalpha (Str[i])) ans2[k++]=str[i];
            else if (str[i]-' 0 ' <=9&&str[i]-' 0 ' >=0) ans1[g++]=str[i];
            } ans1[g]= ' + ';
            ans2[k]= ' + ';
            cout<< "R" <<ans1<< "C";
            Ans=altonum (ANS2);
        cout<<ans<<endl;
}} 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.