【例6.3】删数问题(Noip1994)

【例6.3】删数问题(Noip1994)

链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1321


时间限制: 1000 ms         内存限制: 65536 KB

【题目描述】

输入一个高精度的正整数n,去掉其中任意s个数字后剩下的数字按原左右次序组成一个新的正整数。编程对给定的n和s,寻找一种方案使得剩下的数字组成的新数最小。

输出新的正整数。(n不超过240位)

输入数据均不需判错。

【输入】

n

s

 

【输出】

最后剩下的最小数。

【输入样例】

175438
4

【输出样例】

13
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int main()
{
    string n;
    int s;
    cin>>n;
    int l=n.length();
    cin>>s;
    for(int i=1;i<=s;i++)
    {
        for(int j=0;j<l-1;j++)
            if(n[j]>n[j+1])
            {
                for(int k=j;k<l;k++)n[k]=n[k+1];
                break;
            }
        l--;
    }
    int i=0;
    while(i<l&&n[i]-'0'==0)i++;
    if(i==l)cout<<"0"<<endl;
    else for(;i<l;i++)cout<<n[i];
}

 

posted @ 2017-10-29 15:52  Ed_Sheeran  阅读(857)  评论(0编辑  收藏  举报