-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path0045.cpp
More file actions
49 lines (46 loc) · 857 Bytes
/
0045.cpp
File metadata and controls
49 lines (46 loc) · 857 Bytes
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
// 0045.名字的漂亮度
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int score(string s)
{
map<char,int> mp;
vector<int> v;
int sum = 0;
for(int i = 0; i < s.size(); i++)
{
if (mp.find(s[i]) == mp.end()) {
mp[s[i]] = 1;
}else {
mp[s[i]] ++;
}
}
for(auto it = mp.begin(); it != mp.end(); it ++)
{
v.push_back(it->second);
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for(int i = 0; i < v.size(); i++)
{
sum += (26-i)*v[i];
}
return sum;
}
int main()
{
int n;
string s;
while(cin >> n)
{
getchar();
for(int i = 0; i < n; i ++)
{
getline(cin, s);
cout << score(s) << endl;
}
}
return 0;
}