题目链接:http://codeforces.com/contest/488

A. Giga Tower

Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from  - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor  - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.

In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,  - 180, 808 are all lucky while42,  - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).

Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.

题意:给出一个定义"lucky number":至少有一位上面是'8' 。现在给一个数a,求一个最小正数b,满足a+b之后是lucky number。

解法:暴力。因为题目要求一个数里面有一个数位上的数字为8就可以,所以不管a是不是luncky number,在枚举个位的时候一定会出现8。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define inf 0x7fffffff
 8 using namespace std;
 9 const int maxn=100+10;
10 int main()
11 {
12     int n;
13     while (scanf("%d",&n)!=EOF)
14     {
15         int num=n;
16         while (1)
17         {
18             num++;
19             int flag=0;
20             int j= num<0 ? -num : num;
21             while (j)
22             {
23                 int k=j%10;
24                 if (k==8) {flag=1;break; }
25                 j /= 10;
26             }
27             if (flag) {printf("%d\n",num-n);break;}
28         }
29     }
30     return 0;
31 }
View Code

相关文章:

  • 2022-12-23
  • 2021-05-31
  • 2021-09-07
  • 2022-01-05
  • 2021-08-12
  • 2021-04-24
  • 2021-12-04
  • 2021-11-19
猜你喜欢
  • 2022-01-03
  • 2022-12-23
  • 2021-08-03
  • 2022-02-13
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案