刪數問題

刪數問題

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

 鍵盤輸入一個高精度的正整數n(≤100位),去掉其中任意s個數字後剩下的數字按照原來的左右次序組成一個新的正整數。編程對給定的n與s,尋找一種方案,使得剩下的數字組成的新數最小。

Input

  輸入有多組 每組包括原始數n,要去掉的數字數s;

Output

 輸出去掉s個數後最小的數

Sample Input

178543  4

Sample Output

13

Hint

 

Source

#include<stdio.h>
#include<string.h>
int main()
{
    int s, i, l;
    char a[108];
    while(scanf("%s %d", a, &s) != EOF)
    {
        while(s--)
        {
            l = strlen(a);
            i = 0;
            while(i < l && a[i] <= a[i + 1])
                i++;
            while(i < l)
            {
                a[i] = a[i + 1];
                i++;
            }
        }
        l = strlen(a);
        i = 0;
        while(i < l && a[i] == '0')
            i++;
        if(i < l)
        {
            while(i < l)
            {
                printf("%c", a[i]);
                i++;
            }
        }
        else printf("0");
        printf("\n");

    }
    return 0;
}



發佈了58 篇原創文章 · 獲贊 1 · 訪問量 7859
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章