zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    webpack 配置别名,解决 import 时路径查找麻烦的问题
    Vue 中 diff 算法后更新 DOM 的方法
    React Native 开发环境搭建
    JavaScript 堆排序详解
    JavaScript 快速排序详解
    websocket 心跳重连
    AJAX 请求后使用 JS 打开新标签页被阻止的解决方法
    auto.js环境搭建
    Mac os 创建pppoe拨号
    mac os IntelliJ IDEA搭建环境
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9054359.html
Copyright © 2011-2022 走看看