Iroha's Obsession

问题 D: Iroha's Obsession

时间限制: 1 Sec  内存限制: 128 MB
提交: 189  解决: 82
[提交][状态][讨论版][命题人:admin]

题目描述

Iroha is very particular about numbers. There are K digits that she dislikes: D1,D2,…,DK.
She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).
However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.
Find the amount of money that she will hand to the cashier.

Constraints
1≤N<10000
1≤K<10
0≤D1<D2<…<DK≤9
{D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}

输入

The input is given from Standard Input in the following format:

N K
D1 D2 … DK

输出

Print the amount of money that Iroha will hand to the cashier.

样例输入

1000 8
1 3 4 5 6 7 8 9

样例输出

2000

提示

She dislikes all digits except 0 and 2.
1The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
 
int main()
{
    int a[10]={0};
//    for(int i=0;i<10;i++)
//    {
//        printf("%d ",a[i]);
//    }
    int n,k;
    int ans = 0;
    int flag = 0;
    int x;
    scanf("%d %d",&n,&k);
    for(int i=0;i<k;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
//    for(int i=0;i<10;i++)
//    {
//        printf("%d ",a[i]);
//    }
    for(int i=n;i<1000000;i++)
    {
        int t = i;
        flag = 0;
        while(t)
        {
            int p = t%10;
            if(a[p]!=0)
            {
                flag = 1;
                break;
            }
            t/=10;
        }
        if(flag==1)
            continue;
        else
        {
             ans = i;
             break;
        }
        //printf("%d ",i);
    }
    printf("%d",ans);
}

 

转载于:https://www.cnblogs.com/hao-tian/p/9054359.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值