题解 | 名字的漂亮度
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; while (cin >> n) { vector<string>str(n); for (int i = 0 ; i < n ; i++) { cin >> str[i]; vector<int>counts(26, 0); for (int j = 0; j < str[i].size(); j++) { if (str[i][j] >= 'a' && str[i][j] <= 'z' ) { counts[str[i][j] - 'a']++; } else if (str[i][j] >= 'A' && str[i][j] <= 'Z') { counts[str[i][j] - 'A']++; } } sort(counts.begin(),counts.end()); int ans = 0; int k = 26; for(int i = 25 ; i >= 0; i--){ ans = (k)* counts[i] + ans; k--; } cout << ans <<endl; } } return 0; } // 64 位输出请用 printf("%lld")