-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1339.cpp
66 lines (61 loc) · 1.44 KB
/
1339.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
bool cmp(pair<int, int> left , pair<int, int> right ) {
return left.second < right.second;
}
int Pow(int k, int n){
if(n==0){
return 1;
}
return k*Pow(10, n-1);
}
int n;
int ans;
int main(void){
cin >> n;
string str;
vector<string> v(8);
map<char, int> m;
for(int i=0; i<n; i++){
cin >> str;
int idx = 0;
for(auto riter=str.rbegin(); riter!=str.rend(); riter++){
v[idx] += *riter;
idx++;
}
}
for(int i=0; i<8; i++){
if(v[i].length() == 0){
continue;
}
for(int j=0; j<v[i].length(); j++){
m[v[i][j]] += pow(10, i);
}
}
vector<pair<char, int>> v2;
copy(m.begin(), m.end(), back_inserter<vector<pair<char, int>>>(v2));
sort(v2.begin(), v2.end(), cmp);
int idx = 9;
for(auto iter=v2.rbegin(); iter!=v2.rend(); iter++){
m[iter->first] = idx--;
}
ans = 0;
for(int i=0; i<8; i++){
if(v[i].length() == 0){
continue;
}
for(int j=0; j<v[i].length(); j++){
// printf("v[%d][%d]: %c\n", i,j,v[i][j]);
// printf("m[v[%d][%d]]: %d\n", i,j,m[v[i][j]]);
ans += (m[v[i][j]]*Pow(10,i));
// printf("ans: %d\n", ans);
}
}
cout << ans;
return 0;
}