题解 | #名字的漂亮度#

名字的漂亮度

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

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int num;
    cin>>num;
    string input[num];
    for(int i=0; i<num; i++)
    {
        cin>>input[i];
        //统计字符的个数(出现过的不再计数)
        int length = input[i].length();
        int number[length];
        int tmp = 0;
        for(int j=0; j<length; j++)
        {
            number[j] = 0;
            if(input[i].find(input[i][j])==j)
            {
                tmp++;
                for(int m=j; m<length; m++)
                {
                    if(input[i][m] == input[i][j])
                    {
                        number[j]++;
                    }
                }
            }
        }
        //计数排序
        for(int j=0; j<length; j++)
        {
            for(int k=0; k<length-j-1; k++)
            {
                if(number[k]<number[k+1])
                {
                    swap(number[k],number[k+1]);
                }
            }
        }
        //计算结果
        int result = 0;
        for(int j=0; j<tmp; j++)
        {
            result += (26-j)*number[j];
        }
        cout<<result<<endl;
    }
    return 0;
}
全部评论

相关推荐

05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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