您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  华为机试题