当前位置: 首页 > news >正文

Day13力扣打卡

打卡记录

在这里插入图片描述

奖励最顶尖的 k 名学生(哈希表+排序)

用哈希表对所有的positive与negative词条进行映射,然后遍历求解。tip:常用的分割字符串的操作:1.stringstream配合getline() [格式buf, string, char]2.string.find()[find未找到目标会返回npos]配合string.substr()

class Solution {
public:vector<int> topStudents(vector<string>& positive_feedback, vector<string>& negative_feedback, vector<string>& report, vector<int>& student_id, int k) {unordered_set<string> pos, neg;for (auto& s : positive_feedback) pos.insert(s);for (auto& s : negative_feedback) neg.insert(s);vector<pair<int, int>> arr;int n = student_id.size();for (int i = 0; i < n; ++i) {stringstream ss;ss << report[i];string tmp;int res = 0;while (getline(ss, tmp, ' ')) {if (pos.count(tmp)) res += 3; else if (neg.count(tmp)) res--;}arr.push_back({-res, student_id[i]});}sort(arr.begin(), arr.end());vector<int> ans(k);for (int i = 0; i < k; ++i) ans[i] = arr[i].second;return ans;}
};
http://www.lryc.cn/news/209842.html

相关文章:

  • 独立开发者知识贴
  • 软考系列(系统架构师)- 2009年系统架构师软考案例分析考点
  • C语言每日一题(21)删除排序数组中的重复项
  • 如何快速解决d3dcompiler_43.dll缺失问题?五种方法快速解决
  • mongodb数据迁移的方法
  • Spring MVC 中文文档
  • RedissonCach的源码流程
  • spring-基于注解管理bean
  • 数据挖掘(7.1)--数据仓库
  • Vue3问题:如何实现密码加密登录?前后端!
  • 【爬虫】python打包可执行程序(ui界面制作完成后)
  • 取Dataset子集(pytorch)
  • 如何选择消息队列
  • 读取mysql数据库表结构生成接口文档
  • 【MySQL索引与优化篇】InnoDB数据存储结构
  • Go学习第十二章——Go反射与TCP编程
  • uniapp编译微信小程序富文本rich-text的图片样式不生效原因
  • Django实战项目-学习任务系统-任务管理
  • ubuntu18.04设置开机自动启动脚本(以自动启动odoo命令行为例讲解)
  • golang工程——grpc-gateway 转发http header中自定义字段到grpc上下文元数据
  • CPU眼里的C/C++: 1.3 汇编级单步调试函数执行过程
  • 数据结构时间复杂度(补充)和空间复杂度
  • Mac-postman存储文件目录
  • JAVA面试题简单整理
  • dd命令用法学习,是一个功能强大的工具
  • Games104现代游戏引擎笔记 网络游戏进阶架构
  • Apollo 快速上手指南:打造自动驾驶解决方案
  • C现代方法(第14章)笔记——预处理器
  • Kafka KRaft模式探索
  • LVS-keepalived实现高可用