zoukankan      html  css  js  c++  java
  • Codeforces550C(SummerTrainingDay01-H)

    C. Divisibility by Eight

    time limit per test : 2 seconds
    memory limit per test : 256 megabytes
    input : standard input
    output : standard output

    You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

    Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

    If a solution exists, you should print it.

    Input

    The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

    Output

    Print "NO" (without quotes), if there is no such way to remove some digits from number n.

    Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

    If there are multiple possible answers, you may print any of them.

    Examples

    input

    3454

    output

    YES
    344

    input

    10

    output

    YES
    0

    input

    111111

    output

    NO


     1 //2017-08-01
     2 #include <cstdio>
     3 #include <iostream>
     4 #include <cstring>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 const int N = 110;
    10 char num[N];
    11 
    12 int main()
    13 {
    14     while (scanf("%s", num) != EOF)
    15     {
    16         int n = strlen(num);
    17         bool fg = false;
    18         for (int i = 0; i < n; i++)
    19         {
    20             if (num[i] == '0')
    21             {
    22                 fg = true;
    23                 printf("YES
    0
    ");
    24                 break;
    25             }
    26         }
    27         if(fg)continue;
    28         for (int a = 8; a < 1000; a += 8)
    29         {
    30             int tmp = a;
    31             for (int i = n - 1; i >= 0; i--)
    32             {
    33                 if (num[i] - '0' == tmp % 10)
    34                 {
    35                     tmp /= 10;
    36                 }
    37             }
    38             if (!tmp && !fg)
    39             {
    40                 printf("YES
    %d
    ", a);
    41                 fg = true;
    42                 break;
    43             }
    44         }
    45         if (!fg)
    46             printf("NO
    ");
    47     }
    48 
    49     return 0;
    50 }
  • 相关阅读:
    网络系统集成实习——第四天——2017.9.10
    网络系统集成实习——第三天——2017.9.9
    网络系统集成实习——第二天——2017.9.8
    网络系统集成实习——第一天——2017.9.6
    如何查找文献及规范参考文献引用格式(以石家庄铁道大学图书馆为例)
    MATLAB数值分析实验
    MATLAB常微分方程的数值解法
    MATLAB数值积分法
    【工匠大道】博客园小技巧
    【夯实PHP基础】PHP 面向对象
  • 原文地址:https://www.cnblogs.com/Penn000/p/7271975.html
Copyright © 2011-2022 走看看