题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <iostream> #include <bits/stdc++.h> #include <vector> using namespace std; bool cmp (int &a, int &b){ return a >b; } int main() { int n ; cin>>n; while (n--){ string str; cin >>str; unordered_map<char, int> map; for (auto ch : str) map[ch]++; vector<int> vec; for (auto it : map) vec.push_back(it.second); sort(vec.begin(), vec.end(), cmp); int result = 0, index = 26; for (auto x : vec){ result += x * index; index--; } cout << result<<endl; } } // 64 位输出请用 printf("%lld")