#include <iostream> #include <algorithm> #include <map> using namespace std; int main(){ string str; cin>>str; map<char,int> hashMap; // 用来统计字符的个数的,并且会进行排序 // 遍历str for(auto &ele: str){ hashMap[ele]++; // 不能用multimap,没有重载[]运算符 } // 此时的map是按照char进行排序的,问题来到了怎样在map中找到最小的int // 希望有按照int进行排序的 multimap<int,char> hashMapIndex; for(auto &[ch,num]: hashMap){ hashMapIndex.insert({num,ch}); } // 找到最小的两个 auto it = hashMapIndex.begin(); while(it->first == (++it)->first){ // 都删掉 str.erase(remove(str.begin(),str.end(),(--it)->second),str.end()); ++it; } // 删掉后一个 str.erase(remove(str.begin(),str.end(),(--it)->second),str.end()); // 输出字符串 cout<<str<<endl; return 0; }