题解 | #名字的漂亮度#
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
string str;
vector<string> names;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str;
names.push_back(str);
}
vector<int> beauty;
for (auto name : names) {
map<char, int> keyMap;
for (auto c : name) {
auto ret = keyMap.insert({c, 1});
if (!ret.second) {
ret.first->second++;
}
}
multimap<int, char> valueMap;
for (auto m : keyMap) {
valueMap.insert({m.second, m.first});
}
int value = 26;
int sum = 0;
for (auto it = valueMap.crbegin(); it != valueMap.crend(); ++it) {
sum += value * it->first;
value--;
}
beauty.push_back(sum);
}
for (auto b : beauty) {
cout << b << endl;
}
return 0;
}
查看12道真题和解析