标签:
A
给出一个数a, b为一个正数,如果a+b含有8,则称为吉祥的数字,找出最小的b
枚举b就可以了-
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 int num[10]={1000000000,100000000,10000000,1000000,100000,10000,1000,100,10}; 8 9 int judge(long long x) 10 { 11 if(x<0) x=-x; 12 13 if(x/num[0]==8||x/num[1]%10==8||x/num[2]%10==8||x/num[3]%10==8||x/num[4]%10==8||x/num[5]%10==8||x/num[6]%10==8||x/num[7]%10==8||x/num[8]%10==8||x%10==8) 14 return 1; 15 return 0; 16 } 17 int main() 18 { 19 long long a,x,y,i; 20 int flag=1; 21 cin>>a; 22 for(i=1;i<=1000000000;i++) 23 { 24 x=a+i; 25 if(judge(x)||judge(y)) 26 { 27 flag=1; 28 break; 29 } 30 31 } 32 if(flag) printf("%I64d\n",i); 33 else printf("-1\n"); 34 }
Codeforces Round #278 (Div. 2)
标签:
原文地址:http://www.cnblogs.com/wuyuewoniu/p/4302914.html