sgu 296. Sasha vs. Kate 貪心

296. Sasha vs. Kate

Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



During the regular Mars's World Finals Subregional Programming Contest a boy Sasha lost N "Mars" bars of chocolate to a girl Kate. But for two years already Sasha does not hurry to pay his debt. And now Sasha and Kate decided that Sasha will give Kate P chocolate bars, where number P can be obtained from the number N by removing exactly K decimal digits. Sasha generously let Kate to choose digits to be removed. Your task is to find out how many bars Sasha will give Kate. Of course Kate will choose K digits from the number N in such a way that the resulting number P would be maximal.

Input
The first line of the input file contains two integer numbers N and K (1≤ N≤ 101000; 0≤ K≤ 999). Number K is strictly less than the number of digits in NN will not have any leading zeros.

Output
Output the unknown P.

Example(s)
sample input
sample output
1992 2
99

sample input
sample output
1000 2
10


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1005];
int k;
int main()
{
    scanf("%s %d",s,&k);
    int len=strlen(s);
    int w=len-k;
    int index=-1;
    while(w)
    {
        char mx='0';
        for(int i=index+1;i<=index+1+k;i++)mx=max(mx,s[i]);
        for(int i=index+1;i<=index+1+k;i++)
        {
            if(s[i]==mx)
            {
                printf("%c",s[i]);
                w--;
                k-=(i-index-1);
                index=i;
                break;
            }
        }
    }
    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章