题解 | #名字的漂亮度#
名字的漂亮度
http://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <bits/stdc++.h> using namespace::std;
int main() {
int num;
cin >> num;
while (num--) {
int i = 26;
int sum = 0;
int cnt[26] = {0};
string str;
cin >> str;
for (auto c : str) {
c = tolower(c);
++cnt[c-'a'];
}
sort(cnt, cnt + 26, [](const int c1, const int c2) { return c1 > c2; });
for (auto const &c : cnt) {
sum += c * i--;
}
cout << sum << endl;
}
return 0;
}