Codeforces 1b. Spreadsheets (simulation)

Source: Internet
Author: User
Tags integer numbers

Link: B

B. spreadsheetstime limit per test10 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard 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.


The first line of the input contains integer numberN(1? ≤?N? ≤? 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.


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

Sample test (s) Input


Two different expression methods are used to represent the rows and columns!

The Code is as follows:

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 117; typedef _ int64 ll; int is_letter (char C) {If (C> = 'A' & C <= 'Z') return 1; return 0;} int is_num (char C) {If (C> = '0' & C <= '9') return 1; return 0 ;}int main () {ll t; char s [maxn]; scanf ("% i64d", & T); getchar (); While (t --) {gets (s); int Len = strlen (s); int K = 0; for (INT I = 0; I <Len; I ++) {If (is_letter (s [I]) & is_num (s [I + 1]) {k ++ ;}}if (k = 2) // r23c55 FORM {ll I, j; ll T1 = 0, T2 = 0; for (I = 1 ;; I ++) {If (is_num (s [I]) T1 = T1 * 10 + s [I]-'0'; else break ;} for (j = I + 1; j <Len; j ++) {If (is_num (s [J]) t2 = T2 * 10 + s [J]-'0'; else break;} // printf ("T1: % i64d t2: % i64d \ n", T1, t2); char a [maxn]; I = 0; while (T2) {ll TT = t2 % 26; A [I ++] = tt + 'a'-1; t2/= 26; If (TT = 0) // note {T2 --; A [I-1] = 'Z' ;}} for (j = I-1; j> = 0; j --) {printf ("% C", a [J]);} printf ("% i64d \ n", T1 );} else // bc23 FORM {ll I, j; ll T3 = 0, T4 = 0; for (I = 0; I ++) {If (is_num (s [I]) break; T3 = T3 * 26 + (s [I]-'A' + 1) ;}for (j = I; j <Len; j ++) {t4 = T4 * 10 + s [J]-'0';} printf ("R % i64dc % i64d \ n", T4, t3) ;}} return 0;}/* 99r23c55bc23r26c78bz26 */

Codeforces 1b. Spreadsheets (simulation)

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: 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.