## 中石油 2.26

6450: Iroha’s Obsession

[提交] [状态] [讨论版] [命题人: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.

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<stdio.h>
#include<string.h>
using namespace std;
typedef long long int ll;
int main()
{
ll n,k,a={0},d,vis={0},cnt=1,flag=0;
int p;
scanf("%lld%lld",&n,&k);
ll z=n;
int i,j;
for(i=1;i<=k;i++)
{
scanf("%d",&d[i]);
vis[d[i]]=1;
}
for(i=0;i<=10;i++)
{
if(vis[i]==0)
{
p=i;
break;
}
}
while(n)
{
a[cnt++]=n%10;
n=n/10;
}
for(i=cnt-1;i>=1;i–)
{
// printf("!\n");
if(vis[a[i]]==1)
{
while(vis[a[i]]==1)
{
// printf("!\n");
a[i]=a[i]+1;
if(a[i]10)
{
a[i]=p;
i=i+1;
a[i]=a[i]+1;
}
if(i
cnt)
{
a[i]=1;
while(vis[a[i]]1)
{
a[i]=a[i]+1;
}
printf("%lld",a[cnt]);
for(j=cnt-1;j>=1;j–)
printf("%d",p);
printf("\n");
return 0;
}
}
k=i;
for(j=cnt-1;j>=1;j–)
{
if(j>=k)
printf("%lld",a[i]);
else
printf("%d",p);
if(j
1)
return 0;

``````        }
}

}
printf("%lld\n",z);
return 0;
``````

}`

0条评论