Huawei junior-name beauty

Source: Internet
Author: User

It is worth noting that for each name: the beauty of the name = 26 * + 25 * with the largest number of letters + 24 * with the second number of letters ......

Source program:

 
# Include <iostream> # include <string> using namespace STD; const int M = 50; int main () {int N, I, J, K, Len; int beauti [m] = {0}; int t; CIN> N; char a [m] [30]; for (I = 0; I <N; I ++) CIN> A [I]; for (I = 0; I <n; I ++) {int B [26] = {0 }; len = strlen (A [I]); For (j = 0; j <Len; j ++) // calculate the occurrence frequency of each letter. {B [A [I] [J]-'a'] ++;} For (k = 0; k <26; k ++) // sort the occurrences of each letter in ascending order. {For (int m = k + 1; m <26; m ++) {If (B [k] <B [m]) {T = B [k]; B [k] = B [m]; B [m] = T ;}}for (Int J = 0, du = 26; j <26, du> = 1; j ++, Du --) // calculate the beauty of a [I] {beauti [I] = beauti [I] + du * B [J];} for (I = 0; I <n; I ++) cout <beauti [I] <Endl; return 0 ;}
Running result:


Conclusion: I think this question is quite good. The only drawback is that the question is not clearly described: the beauty of the name = 26 * + 25 * with the largest number of letters + 24 * with the second number of letters ...... Here, we need to calculate the frequency of occurrence of each letter. The algorithm used here was learned from other people's algorithms. The frequency is also sorted, and the beauty of the name is measured in two ways: letter frequency * letter beauty. Although it is a preliminary question, I personally think it is still possible to examine basic skills ~ Haha, I log on to the Huawei OJ platform every day. I hope I can join Huawei ~

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.