fork(3) download
  1. #include<iostream>
  2. #include<string>
  3. #include<cstring>
  4. #include<cstdio>
  5. #include<cstdlib>
  6. #include <string>
  7. #include <algorithm>
  8. using namespace std;
  9. int t,len,i,tp=26;
  10. long long ans=0,parentalpha[26],alphavalue;
  11. string A,B;
  12.  
  13. int main()
  14. {
  15.  
  16. scanf("%d\n",&t);
  17. while(t--)
  18. {
  19. for(i=0;i<26;i++)
  20. {
  21. parentalpha[i]=0;
  22. }
  23. tp=26;
  24. ans=0;
  25. std::string str;
  26. std::getline(cin, str);
  27. std::transform(str.begin(), str.end(), str.begin(), ::tolower);
  28. //cout<<str<<"\n";
  29. len=str.length();
  30. for(i=0;i<len;i++)
  31. {
  32. if(int(str[i])>=97&&int(str[i])<=122)
  33. {
  34. alphavalue=(str[i])-97;
  35. parentalpha[alphavalue]+=1;
  36. }
  37. }
  38. /*for(i=0;i<26;i++)
  39.   {
  40. printf("%d ",parentalpha[i]);
  41. }
  42. cout<<"\n";*/
  43. std::sort(parentalpha, parentalpha + 26);
  44. /*for(i=0;i<26;i++)
  45.   {
  46. printf("%d ",parentalpha[i]);
  47. }
  48. cout<<"\n";*/
  49. for(i=25;i>=0;i--)
  50. {
  51. ans=ans+(long long)(parentalpha[i]*tp);
  52. tp--;
  53. }
  54. printf("%lld\n",ans);
  55. }
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 3036KB
stdin
5
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