题目描述:https://pycoder.blog.csdn.net/article/details/124775982
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int myCmp(const void *a, const void *b)
{
int *aa = (int *)a;
int *bb = (int *)b;
return *bb - *aa;
}
int main(void) {
char str[1000] = {0};
int hash[26] = {0};
int sum;
while (gets(str) != NULL) {
sum = 0;
memset(hash, 0, sizeof(hash));
for (int i = 0; i < strlen(str); i++) {
hash[str[i]-'a']++;
}
qsort(hash, 26, sizeof(hash[0]), myCmp);
for (int i = 0; i < 26; i++) {
sum += hash[i] * (26 - i);
}
printf("%d\n", sum);
}
return 0;
}