1182 Perfect string title Source: Facebook Hacker Cup selection base time limit: 1 seconds space limit: 131072 KB Score: 5 Difficulty: 1-level algorithm collection concern John thinks that the perfect degree of a string is equal to the perfection of all the letters in it. The perfect degree of each letter can be assigned by you, different letters of the perfect degree, respectively, corresponding to an integer between 1-26. John doesn't care about the letter case. (That is, the letters F and F) are of the same degree of perfection. Given a string, output its maximum possible degree of perfection. For example: Dad, you can assign 26 to d,25 to assign to a, so that the entire string has a perfect degree of 77. Input
Enter a string s (s of length <= 10000), s in which there are no characters other than letters.
Output
You assign 1-26 to different letters, so that the perfect degree of the string s is the maximum, the output of this perfect degree.
Input example
Dad
Output example
77
"Analysis": the general need to operate on each character is not a string, with a char character array. Ask for the most general reverse order.
"Code":
#include <bits/stdc++.h>using namespacestd;#defineLL Long LongLL N;inth[ -];intMain () {stringA; CIN>>A; for(intI=0; I<a.length (); i++) {A[i]=ToLower (A[i]); H[a[i]-'a']++; } sort (H,h+ -); LL ans=0; for(intI= -; i>=0; i--) {ans+=h[i]*i;//I'm just asking you this.} cout<<ans<<Endl; return 0;}View Code
51nod 1182 Perfect string "string sort + hash"