1. 首先,采用unordered_map来存储这样一个统计信息,其中key为字符,value为该字符出现的序列。
  2. 第二部,先是一个循环,每次迭代寻找次数为MinTimes的字符并将原串中置换为空格,没有最小次数为MinTimes的字符,则MinTimes加1往下循环。当当前次数的所有字符都替换为空格后,再统一将其删除,这样就得到了最终的字符串了。
#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;

int main()
{
    string s;
    while ( cin >> s ){
        unordered_map<char, vector<int>> m;
        int MinTimes = 1;
        bool Del_flag = false;
        // 遍历一遍s统计数量,并记录下
        for (int i = 0; i< s.length(); i++){
            if (!m.count(s[i])){
                m[s[i]] =  {i};
            }
            else{
                m[s[i]].push_back(i);
            }
        }
        while(MinTimes <= s.length()){
            for(auto & it : m){
                if (it.second.si***Times){
                    Del_flag = true;
                    for (int i : it.second){
                        s[i]=' ';
                    }

                }
            }
            if (!Del_flag){
                MinTimes ++;
            }
            else{
                int loc;
                while((loc = s.find(' ')) != string::npos){
                    s.erase(loc, 1);
                }
                break;
            }
        }
        cout << s <<endl;
    }
    return 0;
}