题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<string> minzi; for (int i = 0;i < n;i++) { string strs; cin >> strs; minzi.push_back(strs); } for (auto it : minzi) { map<char,int> data; for (int i = 0;i < it.size();i++) { data[it[i]] += 1; } std::vector<std::pair<char, int>> temp(data.begin(), data.end()); std::sort(temp.begin(), temp.end(), [](const std::pair<char, int>& a, const std::pair<char, int>& b) { return a.second > b.second; }); int outdata = 0; int j = 0; for (auto iter : temp) { outdata += (26 - j) * iter.second; j += 1; if (j == temp.size()) { break; } } cout << outdata << endl; } } // 64 位输出请用 printf("%lld")