0711华为机试-名字的漂亮度

来源:互联网 发布:网页视频下载软件 编辑:程序博客网 时间:2024/05/17 08:58

坑爹的机试题,题很容易,线下通过,线上调试了很久,最后还是通过了

#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;}
原创粉丝点击