题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { string num; int count; int num_to_c = 26; vector<int> store(26); getline(cin,num); count = stoi(num); int i = 1; int res = 0; string tem_str; while(i<=count){ getline(cin,tem_str); //cout<<tem_str<<endl; for(int j = 0;j<tem_str.size();j++){ store[tem_str[j]-'a']++; //cout<<tem_str[j]-'a'<<':'<<store[tem_str[j]-'a']<<endl; } sort(store.begin(),store.end()); for(int k = store.size()-1;k>=0;k--){ if(store[k]!=0){ res+=num_to_c*store[k]; num_to_c--; }else{ break; } } cout<<res<<endl; num_to_c = 26; std::fill(store.begin(), store.end(), 0); res = 0; tem_str.clear(); i++; } } // 64 位输出请用 printf("%lld")