codeforces 488A. Giga Tower 解题报告

题目链接:http://codeforces.com/problemset/problem/488/A

题目意思:给出一个数a,范围是[-10^9, 10^9],问它最少需要加的一个正整数 b 是多少,条件是加完之后这个数至少有一位有 8.

  有一个小小的意外,改了好久啊~~~~负数的情况,需要乘上 -1,再判断。

   

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 using namespace std;
 6 
 7 typedef __int64 LL;
 8 
 9 bool get_eight(LL x)
10 {
11     if (x < 0)
12         x *= (-1);
13     while (x)
14     {
15         LL k = x % 10;
16         if (k == 8)
17             return true;
18         x /= 10;
19     }
20     return false;
21 }
22 
23 int main()
24 {
25     #ifndef ONLINE_JUDGE
26         freopen("in.txt", "r", stdin);
27     #endif // ONLINE_JUDGE
28 
29     LL a;
30     while (scanf("%I64d", &a) != EOF)
31     {
32         LL cnt = 1;
33         for (LL i = a+1; ; i++)
34         {
35             if (!get_eight(i))
36                 cnt++;
37             else
38                 break;
39         }
40         printf("%I64d\n", cnt);
41     }
42     return 0;
43 }

 

posted @ 2014-11-22 15:55  windysai  阅读(273)  评论(0编辑  收藏  举报