当前位置: 首页 > 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.lryc.cn/news/590081.html

相关文章:

  • python基础②-数据结构
  • 【DataWhale】快乐学习大模型 | 202507,Task02笔记
  • 牛客:HJ26 字符串排序[华为机考][map]
  • 3d max 图片(参考图)的导入
  • 设计模式—初识设计模式
  • Java大厂面试实录:从Spring Boot到AI大模型的深度技术拷问
  • iOS App 上架流程优化指南 工具组合与常见问题处理经验总结
  • C语言:第07天笔记
  • Ubuntu中man手册不全解决以及man手册中英文切换方法
  • pyJianYingDraft 在 import_srt 字幕添加花字效果
  • 海康线扫相机通过采集卡的取图设置
  • WSL2更新后Ubuntu 24.04打不开(终端卡住,没有输出)
  • 【中文核心期刊推荐】《激光与红外》
  • db.refresh()的重复使用和db.rollback()
  • 随机链表的复制数据结构oj题(CM11)
  • Python练习(4)Python参数传递的20道核心实战练习题(含答案与深度解析)(上)
  • BNN 技术详解:当神经网络只剩下 +1 和 -1
  • 《精华离散制造智能工厂三年规划》81页PPT
  • Git分支管理完全指南:从创建到合并与冲突解决
  • 关于redis各种类型在不同场景下的使用
  • 基于 Python/PHP/Node.js 的淘宝 API 商品数据抓取开发教程
  • django安装、跨域、缓存、令牌、路由、中间件等配置
  • .env文件的配置
  • 搭建云途YTM32B1MD1芯片VSCODE+GCC + Nijia + Cmake+Jlink开发环境
  • python的慈善捐赠平台管理信息系统
  • 将URL地址最后一段中文内容进行URL编码
  • Harmony-Next鸿蒙实战开发项目-仿小米商城App----V2
  • 【18】MFC入门到精通——MFC(VS2019)+ OpenCV 显示图片的3种方法
  • Kotlin集合聚合
  • Maple2025 软件安装教程(Win版)