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

牛客:HJ23 删除字符串中出现次数最少的字符[华为机考][字符串]

学习要点

  1. 注意题目要求
  2. 注意哈希会改变原来顺序

题目链接

        删除字符串中出现次数最少的字符_牛客题霸_牛客网

题目描述

解法:map

#include <bits/stdc++.h>
#include <bits/types/struct_itimerspec.h>
#include <climits>
#include <iostream>
using namespace std;int main() {string line;getline(cin, line);map<char, int> ch_map;for (auto& i : line) {ch_map[i]++;}int min_ch = INT_MAX;char ch;for (auto& i : ch_map) {min_ch = min(min_ch, i.second);}// 若有多个字符出现的次数都最少,则把这些字符都删map<char,int> no_str;for (auto& i : ch_map) {if(min_ch == i.second){no_str[i.first]++;}}// 字符串中其它字符保持原来的顺序。bool flag = false;for (auto& i : line) {if(no_str[i] == 0){flag = true;cout << i;}}// 保证这个字符串至少包含一个字符。if(!flag){cout <<line;}}
// 64 位输出请用 printf("%lld")


文章转载自:
http://chartometer.sxnf.com.cn
http://hero.sxnf.com.cn
http://misuse.sxnf.com.cn
http://exoskeleton.sxnf.com.cn
http://inserted.sxnf.com.cn
http://chirognomy.sxnf.com.cn
http://estrone.sxnf.com.cn
http://disputer.sxnf.com.cn
http://ourari.sxnf.com.cn
http://foredone.sxnf.com.cn
http://saree.sxnf.com.cn
http://conirostral.sxnf.com.cn
http://parcellation.sxnf.com.cn
http://brindled.sxnf.com.cn
http://phenolase.sxnf.com.cn
http://calumniator.sxnf.com.cn
http://portecrayon.sxnf.com.cn
http://tsarist.sxnf.com.cn
http://claqueur.sxnf.com.cn
http://policemen.sxnf.com.cn
http://buckpassing.sxnf.com.cn
http://antipoetic.sxnf.com.cn
http://innocently.sxnf.com.cn
http://snick.sxnf.com.cn
http://viscometer.sxnf.com.cn
http://flyness.sxnf.com.cn
http://rudesby.sxnf.com.cn
http://wrangel.sxnf.com.cn
http://ceresine.sxnf.com.cn
http://austenian.sxnf.com.cn
http://www.dtcms.com/a/280710.html

相关文章:

  • Linux 环境下安装 Node.js v16.13.0 完整指南
  • MongoDB 数据库 启用访问控制
  • Volta现代化的 Node.js 版本管理工具
  • CSRF 攻击原理与实验测试(附可运行测试案例)
  • NineData 社区版 V4.3.0 正式发布!新增 5 条迁移对比链路,全面支持 MariaDB、GaussDB 等数据库
  • [附源码+数据库+毕业论文]基于Spring+MyBatis+MySQL+Maven+vue实现的酒店预订管理系统,推荐!
  • Gitlab跑CICD的时候,maven镜像和pom.xml使用的maven版本冲突导致没办法build成功的解决方法
  • [附源码+数据库+毕业论文+开题报告]基于Spring+MyBatis+MySQL+Maven+jsp实现的车辆运输管理系统,推荐!
  • 2025-7-15-C++ 学习 排序(4)
  • langchain教程10:LCEL
  • 【c++】c++11新特性(右值引用和移动语义)
  • PySpark 常用算子详解
  • 【BUG处理】构建APK时遇到错误:‘flutter‘ 命令未被识别。这通常表示您的系统中未安装Flutter SDK或环境变量配置不正确。
  • 牛客:HJ20 密码验证合格程序[华为机考][字符串]
  • 【源力觉醒 创作者计划】文心4.5 vs DeepSeek vs Qwen 3.0:三大能力硬核实测!谁才是王者?
  • 纸板加工制造学习1
  • CF37E Trial for Chief 题解
  • 青年科学基金项目答辩PPT模板 | 杰青优青ppt设计制作美化 | WordinPPT
  • uni-app 学习笔记:Vuex 持久化数据
  • 【C++】神奇的AVL树
  • Java单元测试JUnit
  • 使用 Java 获取 PDF 页面信息(页数、尺寸、旋转角度、方向、标签与边框)
  • 已知均数与标准差,如何生成一组正态分布数据?
  • EPLAN 电气制图(九):直流电源绘制+端子排绘制
  • 线程(二) linux 互斥
  • JVM——有哪些常见的垃圾收集器
  • Props
  • 时序数据库与AI的融合:智能时代的数据基石
  • 027_国际化与本地化
  • Spring应用抛出NoHandlerFoundException、全局异常处理、日志级别