删数问题
TimeLimit: 1000MS Memory Limit: 65536KB
Problem Description
键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。
Input
输入有多组每组包括原始数n,要去掉的数字数s;
Output
输出去掉s个数后最小的数
Example Input
178543 4
Example Output
13
Hint
Author
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char s[150];
    int l,n;
    while(~scanf("%s %d",s,&n))
    {
        int i;
        while(n>0)
        {
         i = 0;
        l = strlen(s);
        while(i<l&&s[i]<=s[i+1])
        {
           i++;
        }
        while(i<l)
        {
           s[i] = s[i+1];
           i++;
        }
        n--;
        }
        while(s[0]=='0')
        {
           i = 0;
           l = strlen(s);
           while(i<l)
           {
             s[i] = s[i+1];
             i++;
           }
        }
        l = strlen(s);
        if(l==0)  printf("0\n");
        else printf("%s\n",s);
    }
    return 0;
}
/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 0ms
Take Memory: 104KB
Submit time: 2017-01-11 09:45:46
****************************************************/ 

京公网安备 11010502036488号