题解 | #名字的漂亮度#

名字的漂亮度

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

#include <stdio.h> #include <string.h> #define SIZE 10001

int main(void) { int N; int len; int max=0; while(scanf("%d\n",&N) != EOF) { char s[N][SIZE]; for(int i=0;i<N;i++) { len=0; max=0; int n[26]={0}; scanf("%s\n",s[i]); len=strlen(s[i]);

// printf("s:%s\nlen:%d\n",s[i],len); //record for(int j=0;j<len;j++) { for(int k=0;k<26;k++) { if(s[i][j]=='a'+k || s[i][j]=='A'+k) { n[k]++; } } }

/* for(int j=0;j<26;j++) { printf("%d ",n[j]); } printf("\n"); */

    //rang
        int t;
        for(int j=0;j<26;j++)
            for(int k=j+1;k<26;k++)
            {
                if(n[k]>n[j])
                {
                    t=n[k];
                    n[k]=n[j];
                    n[j]=t;
                }
            }

/* for(int j=0;j<26;j++) { printf("%d ",n[j]); } printf("\n"); */ //jisuan int c=26; for(int j=0;j<26;j++) { if(n[j] != 0) { max += n[j]*c; c--; } } printf("%d\n",max); } } return 0;

}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务