-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAllYourBase.cpp
35 lines (24 loc) · 1.03 KB
/
AllYourBase.cpp
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
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
int main(){
int T(0); scanf("%d\n", &T);
for(int currentCase = 1; currentCase <= T; currentCase++){
std::string input; getline(std::cin, input);
std::set<char> symbols;
for(int k = 0; k < input.size(); k++){symbols.insert(input[k]);}
int base = symbols.size();
if(base == 1){base = 2;}
std::map<char,int> dict;
for(std::set<char>::iterator iter = symbols.begin(); iter != symbols.end(); iter++){dict.insert(std::pair<char,int>(*iter,-1));}
dict[input[0]] = 1;
for(int k = 1; k < input.size(); k++){if(input[k] != input[0]){dict[input[k]] = 0; break;}}
int nextNumber(2);
for(int k = 0; k < input.size(); k++){if(dict[input[k]] < 0){dict[input[k]] = nextNumber++;}}
long long power(1), total(0);
for(int k = input.size() - 1; k >= 0; k--){total += power * dict[input[k]]; power *= base;}
printf("Case #%d: %lld\n", currentCase, total);
}
return 0;
}