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 ~