删数问题
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。
Input
输入有多组 每组包括原始数n,要去掉的数字数s;
Output
输出去掉s个数后最小的数
Example Input
178543 4
Example Output
13
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n, a, i, k; char s[200]; while(scanf("%s %d", s, &n) != EOF) { for(k = 1; k <= n; k++) { a = strlen(s); i = 0; while(i < a && s[i] <= s[i + 1]) { i++; } while(i < a) { s[i] = s[i + 1]; i++; } } a = strlen(s); i = 0; while(i < a - 1 && s[i] == '0') i++; for(; i < a; i++) { printf("%c", s[i]); } printf("\n"); } return 0; }