fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cctype>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <string.h>
  8.  
  9. using namespace std;
  10.  
  11. int main(int argc, char *argv[]) {
  12. ifstream stream(argv[1]);
  13.  
  14. string str;
  15. while(getline(cin,str,'\n'))
  16. {
  17. int sum = 0;
  18. int length = str.length();
  19. for(int x = 0; x < length; x++) {
  20. char c = str[x];
  21. if(isalpha(c)) ///only for characters
  22. str[x] = tolower(str[x]);
  23.  
  24. }
  25. int arr[26] = {0};
  26. int index = 0;
  27. for(int x = 0; x < length; x++)
  28. {
  29. char c = str[x];
  30. if(isalpha(c)) { ///only for characters
  31. index = str[x] - 97;
  32. arr[index]++;
  33. }
  34. }
  35. sort(arr,arr+26);
  36. int num = 26;
  37.  
  38. for(int x = 25; x >= 0; x--)
  39. {
  40. sum = sum + (arr[x]*num);
  41. num--;
  42. }
  43. cout << sum << endl;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 2824KB
stdin
ABbCcc
Good luck in the Facebook Hacker Cup this year!
Ignore punctuation, please :)
Sometimes test cases are hard to make up.
So I just go consult Professor Dalves
stdout
152
754
491
729
646