0711华为机试-名字的漂亮度
2017-07-11 17:21
239 查看
坑爹的机试题,题很容易,线下通过,线上调试了很久,最后还是通过了
#include<iostream> #include<vector> #include<string> #include<cctype> #include<algorithm> using namespace std; int main() { int n; string str; while (cin>>n) { while (n--) { cin >> str; vector<int>a(26, 0); int count = 0; for (int i = 0; i < (int)str.size(); ++i) { if (isupper(str[i])) a[str[i] - 'A' + 0]++; else a[str[i] - 'a' + 0]++; } int x = 26; sort(a.begin(), a.end()); for (int i = 25; i >= 0; i--) if (a[i]) count += a[i] * x--; cout << count << endl; } } return 0; }
相关文章推荐