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}
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
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); }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· ASP.NET Core - 日志记录系统(二)
· .NET 依赖注入中的 Captive Dependency
· .NET Core 对象分配(Alloc)底层原理浅谈
· 聊一聊 C#异步 任务延续的三种底层玩法
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(一):从.NET IoT入
· .NET 开发的分流抢票软件,不做广告、不收集隐私
· ASP.NET Core - 日志记录系统(二)
· 一个超经典 WinForm,WPF 卡死问题的终极反思
· 实现windows下简单的自动化窗口管理