Codeforces Round #278 (Div. 2)---A. Giga Tower

Source: Internet
Author: User
Tags abs

Giga Tower
Time limit per test 1 second memory limit per test megabytes input standard input output standard output

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

In Cyberland, it was believed that the number "8" was a lucky number (that's why Giga Tower have 8 888 888 888 FLOORS above t He ground), and, an integer are lucky, if and only if their decimal notation contains at least one digit "8". For example, 8,-808, Lucky While42,-is not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck'll always be with you (well, this rou nd is #278, also lucky, huh?).

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

The only line of input contains an integer a (-109≤a≤109). Output

Print the minimum B in a line. Sample Test (s) input

179
Output
1
Input
-1
Output
9
Input
18
Output
10
Note

For the first sample, he had to arrive on the floor numbered 180.

For the second sample, he'll arrive at 8.

Note that B should was positive, so the answer for the third sample was, not 0.





Title: Give a number n, plus k, so that n contains the number 8. Ask for the smallest positive integer k.



Problem-solving ideas: In fact, the biggest k of the subject (n = =-8 o'clock), directly in the face of violent search, and then each to determine whether it contains 8 can. Note, however, that when judging, if you are directly taking the mold, you should pay attention to-8 10 = = 8.




AC Code:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm >
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff

Long long A;

int check (long long x) {
    int flag = 0;
    while (x) {
        int f = x%10;
        if (ABS (f) = = 8) {        //note is ABS (f)
            flag = 1;
            break;
        }
        x/=;
    }
    return flag;
}

int main ()
{
    #ifdef sxk
        freopen ("In.txt", "R", stdin);
    #endif
    long long n;
    while (scanf ("%lld", &n)!=eof)
    {for
        (long long i=1; i<=16 && n+i <= 8888888888 && n-i >=-8888888888; i++) {
            if (check (n+i)) {
                printf ("%lld\n", I);
                Break
    ;
    }}} return 0;
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.