删除字符串中字符最少字符

这是一个C++程序,用于删除输入字符串中出现次数最少的字符。如果有多个人次相同的字符,都会被删除。程序首先使用一个映射来存储每个字符及其出现次数,然后找到最小出现次数,最后遍历字符串并打印出非最少出现次数的字符。
摘要由CSDN通过智能技术生成

删除字符串中字符最少字符

题目描述:
删除字符串中出现次数最少的字符,如果有多个字符出现次数一样,则都删除。
输入描述:
输入 abcdd
字符串中只包含小写英文字母。
输出描述:
dd
示例 1:
输入
abcdd
输出
dd

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

int main(){
	string input_string;
	while(cin>>input_string){
		map<char,int>strmp;
		strmp.clear();
		int cnt = INT_MAX;
		bool flag=true;
		for(auto i:input_string){
			strmp[i]++;
		}
		for(auto i:strmp){
			if(cnt>i.second){
				cnt=i.second;
			}
		}
		for(auto i: input_string){
			if(strmp[i]==cnt){
				continue;
			}
			cout<<i;
			flag=false;
		}
		if(flag){
			cout<<"empty";
		}
		cout<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值