Spreadsheets

Practice this coding question on Coding Gurukul.

Problem statement

Two departments exchange spreadsheet cell addresses, but their software uses different column labels. One writes letters followed by the row number; the other writes the row and column as numbers. A migration utility must recognize the supplied notation and produce the same address in the other notation. Your task Convert every address between letter-column notation such as AA12 and numeric notation such as R12C27. Column letters use A = 1 through Z = 26, followed by AA = 27, AB = 28 and so on. Important details A numeric address has R, one or more row digits, C, then column digits. A letter-style address has one or more uppercase letters followed by row digits. Thus RC12 is a letter-style address, not numeric notation. Row and column numbers are positive and have no leading zeros. Worked example AZ9 refers to row 9 and column 52, so convert it to R9C52. R12C27 becomes AA12. Z1 becomes R1C26, while AA1 becomes R1C27; the transition does not introduce a zero-valued letter.

Input format

Read q, then q valid addresses, one per line.

Output format

Print each converted address on its own line.

Constraints

1 <= q <= 500; row and column numbers are between 1 and 1000000.

Sample input

3
AZ9
R12C27
RC12

Sample output

R9C52
AA12
R12C471

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…