Skip to content

Instantly share code, notes, and snippets.

@krisys
Created January 30, 2013 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisys/4670734 to your computer and use it in GitHub Desktop.
Save krisys/4670734 to your computer and use it in GitHub Desktop.
BeautifulStrings
#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