题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3?tpId=37&tqId=21268&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
int l = str.length();
int a[26] = {0};
for (int j = 0; j < l; j++) {
if (isalpha(str[j])) {
a[str[j] - 'a'] ++;
}
}
sort(a, a + 26, greater<int>());
int sum = 0;
int point = 26;
for (int j = 0; j < 26; j++) {
sum += a[j] * point;
point --;
}
cout << sum << endl;
}
}
// 64 位输出请用 printf("%lld")
查看8道真题和解析
小米集团公司福利 868人发布