zoukankan      html  css  js  c++  java
  • 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
    ", cnt);
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    docker命令总结
    VulToEs
    MYSQL
    MoonStack
    Spring mvc json null
    MySQL
    极光推送
    坑爹的RockSaw和坑爹的windows7
    App接口设计思路
    CSUOJ 1329 一行盒子(数组模拟链表)
  • 原文地址:https://www.cnblogs.com/windysai/p/4115259.html
Copyright © 2011-2022 走看看