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 ≤ 10 1000 ; 0≤  K ≤ 999). Number  K  is strictly less than the number of digits in  N N  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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值