51nod 1182 Perfect string "string sort + hash"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.