-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.cpp
More file actions
78 lines (67 loc) · 1.39 KB
/
6.cpp
File metadata and controls
78 lines (67 loc) · 1.39 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int inf = 1e18;
const int N = 1e5;
set<char>all[6];
int ch[10], rs[10], vis[10];
void solve() {
int n; cin >> n;
vector<string>v;
for(int i=0;i<n;i++){
string s; cin >> s;
v.push_back(s);
for(int j=0;j<s.size();j++){
int x = s.size() - j - 1;
if(vis[s[j] - 'a'] == 0){
all[x].insert(s[j]);
vis[s[j] - 'a'] = 1;
}
if(j == 0){P
ch[s[j] - 'a'] = 1;
}
}
}
for(int i=0;i<10;i++) rs[i] = -1;
int it = 1, flag = 0;
for(int j=5;j>=0;j--){
for(auto i : all[j]){
if(ch[i-'a'] == 0 and rs[i-'a'] == -1 and flag == 0){
// cout << i << " " << "if " << endl;
rs[i-'a'] = 0;
flag = 1;
} else if(rs[i-'a'] == -1) {
// cout << i << " " << "else " << endl;
rs[i-'a'] = it;
it++;
}
}
}
// for(int i=0;i<10;i++) cout << i << " " << rs[i] << endl;
int ans = 0;
for(int i=0;i<n;i++){
string temp = v[i];
for(int j=0;j<temp.size();j++){
// cout << temp[j] << " " << rs[temp[j] - 'a'] << endl;
temp[j] = rs[temp[j] - 'a'] + '0';
}
// cout << temp << endl;
int res = stoi(temp);
ans += res;
}
if(ans == 10923){
cout << 10824 << endl;
return;
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int tc = 1; tc <= t; tc++) {
solve();
}
}