Description:
有一个大整数.不超过1000位.假设有N位.我想删掉其中的任意S个数字.使得删除S位后,剩下位组成的数是最小的. Input:
有多组数据数据,每组数据为两行.第一行是一个大整数.第二行是个整数S,其中S小于大整数的位数. 输入以EOF结束。 Output:
对于每组输入数据,请输出其删除后的最小数. Sample Input:
178543
4
100002
1
Sample Output:
13
2
解题思路:
删除比它下一位大的数字,删除S次即可
注意的是要对答案取出前导0
Source Code:
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ;
const int INF = 0x3f3f3f3f ;
const int offset = ; string ch;
char Min;
int n, m; int main() {
std::ios::sync_with_stdio(false);
int i, j, t, k, u, c, v, p, numCase = ; while (cin >> ch) {
n = ch.size();
cin >> m;
while (m--) {
bool flag = true;//ADD
Min = ch[];
for (i = ; i < n; ++i) {
if (Min > ch[i]) {
for (j = i; j <= n; ++j) {
ch[j - ] = ch[j];
}
flag = false;//ADD
--n;
break;
} else {
Min = ch[i];
}
}
if (flag) { //ADD
--n; //ADD
} //ADD
}
i = ;
for (;;) {
if (ch[i] == '') {
++i;
continue;
}
break;
}
if (i == n) {
cout << << endl;
} else {
for (; i < n; ++i) {
cout << ch[i];
}
cout << endl;
}
} return ;
}