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);
}
复制代码

 

posted @   zangzang  阅读(382)  评论(0编辑  收藏  举报
编辑推荐:
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· ASP.NET Core - 日志记录系统(二)
· .NET 依赖注入中的 Captive Dependency
· .NET Core 对象分配(Alloc)底层原理浅谈
· 聊一聊 C#异步 任务延续的三种底层玩法
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(一):从.NET IoT入
· .NET 开发的分流抢票软件,不做广告、不收集隐私
· ASP.NET Core - 日志记录系统(二)
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· 实现windows下简单的自动化窗口管理
点击右上角即可分享
微信分享提示