Created
January 30, 2013 04:50
-
-
Save krisys/4670734 to your computer and use it in GitHub Desktop.
BeautifulStrings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
#define FOR(i,a,b) for(int i=a;i<b;i++) | |
#define REP(i,a) FOR(i, 0, a) | |
#define VI vector<int> | |
#define all(a) (a).begin(), (a).end() | |
using namespace std; | |
int main(){ | |
int T; | |
cin >> T; | |
cin.ignore(); | |
FOR(tc, 1, T+1){ | |
string s; | |
getline(cin, s); | |
int n = s.length(); | |
VI freq(26, 0); | |
REP(i, n){ | |
char c = tolower(s[i]); | |
if(c >= 'a' && c <= 'z') | |
freq[c - 'a']++; | |
} | |
sort(all(freq)); | |
reverse(all(freq)); | |
long long res = 0; | |
REP(i, 26){ | |
res += freq[i] * (26 - i); | |
} | |
cout << "Case #" << tc << " : " << res << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment