-
Notifications
You must be signed in to change notification settings - Fork 23
/
excel sheet part ii
39 lines (34 loc) · 781 Bytes
/
excel sheet part ii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
Given a string S that represents column title of an Excel sheet, find the number that represents that column.
In excel A column is number 1, AA is 27 and so on.
Input:
The first line contains an integer T, depicting total number of test cases. T testcases follow. Each testcase contains a single line of
input containing string S.
Output:
For each testcase, in a new line, print the column number.
Constraints:
1 ≤ T ≤ 100
1 ≤ |S| <=7
Example:
Input
2
A
AA
Output
1
27
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t; cin>>t;
while(t--){
string k; cin>>k;
long int column=0;
for(int i=0; i<k.length(); i++){
column = column + (k[k.length()-i-1]-'A'+1)*pow(26.0, float(i));
}
cout<<column<<endl;
}
return 0;
}