中石油 2.26

题目链接
可惜 因为乱加return 0;多花了好长时间 ,下次记着…
6450: Iroha’s Obsession
时间限制: 1 Sec 内存限制: 128 MB
提交: 426 解决: 182
[提交] [状态] [讨论版] [命题人: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<stdio.h>
#include<string.h>
using namespace std;
typedef long long int ll;
int main()
{
ll n,k,a[1000]={0},d[1000],vis[1000]={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;

}`

猜你喜欢

转载自blog.csdn.net/qq_43559193/article/details/88034504
0条评论
添加一条新回复