• 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);
    }
  • 相关阅读:
    flex兼容写法
    多行文字,最后一行省略号(适用于移动端)
    checkbox样式修改
    响应式布局
    微信常用的页面跳转
    css小技巧(清除滚动条)
    JS学习---PHP浅识
    qml 画页迁移
    list滚动条Scroll 偏移和长度计算公式总结
    qml listview关键字高亮
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9054359.html
Copyright © 2020-2023  润新知