题解 | 名字的漂亮度

名字的漂亮度

https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
    int A=*(const int*)a;
    int B=*(const int*)b;
    if(A<B) return 1;
    if(A>B) return -1;
    return 0;
    }
int main() {
    char a;
    int n,i;
    scanf("%d",&n);;
    getchar();  
    int c[n];
    for(i=0;i<n;i++){
        int hs[26]={0};
       scanf("%c",&a);  
        while (a!='\n') {
        hs[a-97]++;
        scanf("%c",&a);
        }
    qsort(hs, 26, sizeof(int), cmp);
    int s=0,j=26;
    for (int k=0;k<26;k++){
        if(hs[k]>0) {s=s+j*hs[k];
        j--;
    }
}
    c[i]=s;

    }
    for(i=0;i<n;i++)
     printf("%d\n",c[i]);
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 17:04
点赞 评论 收藏
分享
等闲_:小红书基本不区分日常和暑期,你是应届实习时间够了就有转正机会,只要部门有hc
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务