Spreadsheet Columns
Output: Standard Output (stdout)
Memory limit: 100 megabytes
Time limit: 0.5 seconds
Joseph has recently come into the misfortune of having to use Goggle Sheets for data analysis.
One thing particularly miffing for him is not knowing which column he is on. Goggle Sheets supplies useless labels like F
, BS
, SMH
. These mean nothing to Joseph. He needs numbers dangit.
The way Goggle Sheet's (and in fact most spreadsheet software's) columns are labelled is as follows. Columns number 1 to 26 are labelled A to Z. The next 26 are labelled AA, AB, AC, ..., AY, AZ. The next 26 are BA, BB, BC, ..., BY, BZ. Then CA, CB, etc. After ZZ comes AAA, AAB etc.
Please write a program which takes as input a string of upper case letters not exceeding 6 in length, and prints the number of the corresponding spreadsheet column.
Hint: You may find it useful that the ASCII codes of A
through Z
are the numbers 65 to 90. If you are using Python you can use the ord() function to convert a character to its ASCII code.
Input
The first and only line of input will contain a non-empty string of upper case English letters not exceeding 6 in length.
Output
Output a single integer, the number of the corresponding spreadsheet column.
Subtasks
- Subtask 1 (11%): The column name consists of a single letter.
- Subtask 2 (14%): The column name is at most two letters long.
- Subtask 3 (21%): The column number will be at most 200,000 (column KIVH).
- Subtask 4 (54%): No further constraints.
-
Sample Input 1
C
Sample Output 1
3
-
Sample Input 2
CPP
Sample Output 2
2460