题解 | #名字的漂亮度#

名字的漂亮度

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

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

/*
思路:出现字母最多到最少,对应的漂亮度从26到1。 将大写转化小写字母,字母-’a‘等到对应数字,对所有数字进行排序alpherbet,
alpherbet与1~26相乘求和。
*/
int BeautifulDegreeOfName(string  strIn)
{
    vector<int> alpherbet(26);
    int mostValue = 0;
    for(int j = 0; j < strIn.size(); j++) {
        if(strIn[j] >= 'A' && strIn[j] <= 'Z') {
            strIn[j] = strIn[j] + 32;
        }
    }
    
    for(int i = 0; i < strIn.size(); i++) {
        if(strIn[i] >= 'a' && strIn[i] <= 'z') {
            alpherbet[strIn[i] - 'a'] += 1;
        }
    }
    sort(alpherbet.begin(), alpherbet.end());
    
    for(int i = 0; i < 26; i++) {
        int j = i + 1;
        mostValue += alpherbet[i]*j;
    }
    return mostValue;
   
}
int main()
{
    int n;
    while(cin>>n) {
        for(int i = 0; i < n; i++) {
            string strIn;
            cin>>strIn;
            cout<<BeautifulDegreeOfName(strIn)<<endl;;
        }

    }
}
全部评论

相关推荐

丿南烟丶:黑白模板吧,不要这样花哨的。 主要成就太空了,和获奖融在一起,写一两行就行了。 职业技能不要这样排,就传统的掌握精通什么什么然后举例补充的一些重要技术点。 自我介绍说实话也没啥用,可以删了。 把自己的两个项目方案细节补充上去,为什么这样设计,怎么设计,成果是什么按star法则来写 你要引导面试官来问你的技能和项目,你的获奖和自我介绍别人可能看都不看一眼或者不太在乎,重要的是展示你能干活的能力
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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