思路:典型贪心法
就是每次都除去数字中最小的数字。,建议用字符串来存数字,好用
代码
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct number
{
int i;
char c;
bool operator < (const number b)const {//用c来存字符,用i来存索引
return c < b.c;
}
};
int main(void) {
string n;
cin >> n;
int d;
cin >> d;
vector<number> v;
for (int i = 0; i < n.length(); i++) {
number s;
s.c = n[i];
s.i = i;
v.push_back(s);
}
sort(v.begin(), v.end());//将前d个索引排除不输出
for (int i = 0; i < n.length(); i++) {
int j = 0;
for (; j < d; j++) {
if (i == v[j].i)
break;
}
if (j == d)
cout << n[i];
}
system("pause");
}