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 }

 

转载于:https://www.cnblogs.com/windysai/p/4115259.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值