完美字符串

 1 #include <bits/stdc++.h>
 2 #define _xx ios_base::sync_with_stdio(0);cin.tie(0);
 3 using namespace std;
 4 typedef long long ll;
 5 int main()
 6 {
 7     int a[27];
 8     memset(a, 0, sizeof(a));
 9     string s;
10     cin >> s;
11     for(int i = 0; i < s.size(); i++)
12     {
13         if(s[i] > 'Z') a[s[i] - 'a']++;
14         else a[s[i] - 'A']++;
15     }
16     ll ans = 0;
17     sort(a, a + 27);
18     for(int i = 1; i <= 26; i++)
19         ans += i*a[i];
20     cout << ans << endl;
21     return 0;
22 }
View Code
原文地址:https://www.cnblogs.com/NWUACM/p/6664599.html