Excel to Integer

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 32M

Authors:
Problem type
Allowed languages
Python

Problem Statement

Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.

For example:

A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28 
...

Input Specification

The first line of the input gives the number of test cases, T, T test cases follow. Each test case consists of a line. The line contains the column title c. The column title c will contain only uppercase letters.

Limits

Memory limits: 32MB.

Time limits: 1 second.

1 \leq T \leq 100

1 \leq \text{length of c} \leq 5

(which means the result will in the range [1,12356630])

Test Set 1

Sample case.

Test Set 2

1 \leq \text{length of c} \leq 3

Test Set 3

1 \leq \text{length of c} \leq 4

Test Set 4

1 \leq \text{length of c} \leq 5

Output Specification

For each test case, output one line containing Case #x: y, where x is the case number (starting from 1), and y is the corresponding column number for the given column title c.

Sample Input

2
A
AB

Sample Output

Case #1: 1
Case #2: 28

Hint

for-loop chr/ord positional numeral system

Ref

https://leetcode.com/problems/excel-sheet-column-number/


Comments

There are no comments at the moment.