题解 | #名字的漂亮度#

名字的漂亮度

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

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

int main() {
    int n;
    cin >> n;
    vector<string> minzi;
    for (int i = 0;i < n;i++)
    {
        string strs;
        cin >> strs;
        minzi.push_back(strs);
    }

    for (auto it : minzi)
    {
        map<char,int> data;
        for (int i = 0;i < it.size();i++)
        {
            data[it[i]] += 1;            
        }
        std::vector<std::pair<char, int>> temp(data.begin(), data.end());

		std::sort(temp.begin(), temp.end(), [](const std::pair<char, int>& a, const std::pair<char, int>& b) {
			return a.second > b.second;
		});
		
		int outdata = 0;
		int j = 0;
		for (auto iter : temp)
		{
			outdata += (26 - j) * iter.second;
			j += 1;
			if (j == temp.size())
			{
				break;
			}
		}
		cout << outdata << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-18 12:01
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
LazyBreeze:项目尽量体现你对技术的理解和深度,不是说把中间件用一下就完事了,你项目里面提到集群和分布式,你真在服务器上部署过吗,感觉太假了,第二个项目说自己用了微服务的什么组件,只是用了没有自己的思考,很难让面试官注意到你的简历。针对某几个技术点自己多思考一下,考虑一下有没有别的替代方案,可以写一下,即使没有真的实现
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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