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

牛客:HJ25 数据分类处理[华为机考][哈希][字符串]

学习要点

  1. 写代码时梳理好思路
  2. 写上注释

题目链接

        数据分类处理_牛客题霸_牛客网

题目描述

解法:哈希+set

#include <bits/stdc++.h>
#include <complex>
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;int main() {// 先获得第一行int I_count;cin >> I_count;vector<string> v_str(I_count);for (int i = 0; i < I_count; i++) {cin >> v_str[i];}// 再获得第二行int R_count;cin >> R_count;vector<int> v_int(R_count);for (int i = 0; i < R_count; i++) {cin >> v_int[i];}// cout << endl;// for (auto& i : v_str) {//     cout << i << ' ';// }// cout << endl;// for (auto& i : v_int) {//     cout << i << ' ';// }// cout << endl;// 先处理Rset<int> s_int(v_int.begin(), v_int.end());// cout << endl;// for (auto& i : s_int) {//     cout << i << ' ';// }// cout << endl;// 挂哈希桶unordered_map<int, vector<string>> index_map;for (auto& r_int : s_int) {for (int i = 0; i < I_count; i++) {int pos = v_str[i].find(to_string(r_int));if (pos != string::npos) {index_map[r_int].push_back(to_string(i));}}}// cout << endl;// for (auto& i : index_map) {//     cout << i.first << ' ';//     for(auto&j:i.second)//     {//         cout << j << " ";//     }//     cout << endl;// }// cout << endl;// 构建输出int real_R_count = index_map.size();// cout << real_R_count << endl;int O_count = 0;for (auto& i : index_map) {O_count += i.second.size() * 2;}// cout << O_count << endl;O_count += real_R_count * 2;// cout << O_count << endl;vector<string> O_str;O_str.push_back(to_string(O_count)); // 投入总数for (auto& r_int : s_int) {// 只处理有效Rif (index_map[r_int].size() != 0) {// 投入单规则O_str.push_back(to_string(r_int));// 投入单规则总数O_str.push_back(to_string(index_map[r_int].size()));// 投入后续数组for (int k = 0; k < index_map[r_int].size(); k++) {// 投入下标string t1;t1 += index_map[r_int][k];O_str.push_back(t1);// 投入元素O_str.push_back(v_str[stoi(index_map[r_int][k])]);}}}for (auto& i : O_str) {cout << i << ' ';}
}

http://www.dtcms.com/a/282021.html

相关文章:

  • nextjs+react项目如何代理本地请求解决跨域
  • NSSCTF CVE版签到
  • Win11专业工作站版安装配置要求
  • 实训十一——网络通信原理
  • 【Java】【力扣】94.二叉树的中序遍历
  • 通过 Docker 安装 MySQL
  • 手撕Spring底层系列之:IOC、AOP
  • Web前端性能优化原理与方法
  • 力扣面试150(31/150)
  • React之旅-09 useMemo,优化计算性能的利器
  • Python设计模式深度解析:建造者模式(Builder Pattern)完全指南
  • 浅析BLE/MQTT协议的区别
  • React 源码7:Lane、React和schedule优先级转换
  • Ansible 查看PostgreSQL的版本
  • beautiful-react-hooks库——入门实践常用hook详解
  • React Hooks 数据请求库——SWR使用详解
  • 为来时路,OCM拿证学习和考试
  • 产品经理笔试考试回忆集(2025湖南某国企)
  • 消息中间件(Kafka VS RocketMQ)
  • 每天一个前端小知识 Day 33 - 虚拟列表与长列表性能优化实践(Virtual Scroll)
  • 短剧App/小程序/H5多端开发全流程解析:从架构设计到性能优化
  • WPF 加载和显示 GIF 图片的完整指南
  • 借助AI学习开源代码git0.7之编译和使用
  • Gradle vs Maven:构建工具世纪对决 —— 像乐高积木与标准模型之间的选择艺术
  • SQL中对字符串字段模糊查询(LIKE)的索引命中情况
  • Git问题排查与故障解决详解
  • C++---emplace_back与push_back
  • 工业网络协议桥接设计指南:从LIN到CAN/RS-232的毫秒级互通方案
  • Adobe illustrator、klayout绘制光刻图及其尺寸映射
  • docker的搭建