题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
#include <stdio.h> #include <string.h> #include <ctype.h> int main(){ int n; scanf("%d", &n); char str[n][10002]; for(int k = 0; k < n; k++){ int lab[27] = {0}; scanf("%s", str[k]); for(int j = 0; str[k][j]; j++){ str[k][j] = tolower(str[k][j]); lab[str[k][j] - 'a']++; } int tmp[26]; for(int i = 0; i < 26; i++){ tmp[i] = 26; } for(int i = 0; i < 26; i++){ int max = 0; for(int j = 0; j < 26; j++){ if(lab[j] > max){ max = lab[j]; tmp[i] = j; } } lab[tmp[i]] = 0; } for(int i = 0, j = 26; i < 26; i++){ lab[tmp[i]] = j--; } int sum = 0; for(int j = 0; j < (int)strlen(str[k]); j++){ sum += lab[str[k][j] - 'a']; } printf("%d\n", sum); sum = 0; } return 0; }