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-7 ; const int N = 210 ; const int M = 1100011*2 ; const ll P = 10000000097ll ; const int MAXN = 10900000 ; const int INF = 0x3f3f3f3f ; const int offset = 100 ; 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 = 0; while (cin >> ch) { n = ch.size(); cin >> m; while (m--) { bool flag = true;//ADD Min = ch[0]; for (i = 1; i < n; ++i) { if (Min > ch[i]) { for (j = i; j <= n; ++j) { ch[j - 1] = ch[j]; } flag = false;//ADD --n; break; } else { Min = ch[i]; } } if (flag) { //ADD --n; //ADD } //ADD } i = 0; for (;;) { if (ch[i] == '0') { ++i; continue; } break; } if (i == n) { cout << 0 << endl; } else { for (; i < n; ++i) { cout << ch[i]; } cout << endl; } } return 0; }