A - Giga Tower

Description

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

In Cyberland, it is believed that the number "8" is a lucky number (that‘s why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,  - 180, 808 are alllucky while 42,  - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).

Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will 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 Input

Input

179

Output

1

Input

-1

Output

9

Input

18

Output

10

Hint

For the first sample, he has to arrive at the floor numbered 180.

For the second sample, he will arrive at 8.

Note that b should be positive, so the answer for the third sample is 10, not 0.

代码:

 1 #include<stdio.h>
 2 int function(int n)
 3 {
 4     int t,m=0;
 5     while(n>0)
 6     {
 7         t=n%10;
 8         if(t==8)
 9         {
10             m=1;
11             break;
12         }
13         n=n/10;
14
15     }
16     return m;
17 }
18        int main()
19 {
20     int n,g,i;
21     while(scanf("%d",&n)!=EOF)
22     {
23         for(i=1,n=n+1; i<20; i++)
24         {
25             if(n>=0)g=function(n);
26             else g=function(-n);
27             if(g)break;
28             n++;
29         }
30         printf("%d\n",i);
31     }
32     return 0;
33 }
时间: 2024-10-11 12:16:11

A - Giga Tower的相关文章

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 <c

第一次ACM比赛

在慌忙之中被通知第一次参加ACM比赛,虽然只是校内练习赛,但着实小紧张了一把,所以就卡壳在了第一题上,提交了好多次发现总是不对,刚开始编译错误,到测试数据不过,到最后也都没有写完.回来后思考了一下,算法的确错了,又试了几次,终于写完了.下附第一题 A. Giga Tower time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Gig

UVa 437 The Tower of Babylon

Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story: The babylonians had n typ

Stupid Tower Defense

题目链接 题意: 水平方向上n个1*1的格子,每个格子内部可以种一个植物,经过一个格子的时间为t.一共三种植物:R植物,经过时每秒收到r点伤害:G植物,经过后每秒受到g点伤害:B植物,经过后经过一个格子的时间加上b 2<=n<=1500,0<=r, g, b<=60000,1<=t<=3 分析: 最开始考虑的贪心:先B植物,后G植物,最后B植物,后来才发现是错误的. 首先明白,R植物对答案的影响和位置无关,而B和G植物越早种越好,所以问题就在于B和G的种法上. 状态表示

Koch.Glitsch.KG.TOWER.v5.01.013 1CD

2014.07.18 Bentley.Limcon.03.63.01.14 1CD Bentley.Microstran.Advanced.09.20.01.21 1CD Bentley.MSTower.06.20.01.09 1CD Geometric.Glovius.Pro.v3.9.Win32_64 1CD Latitude Geographics Geocortex Essentials v4.1.3 1CD Synopsys.VCS.vI-2014.03-2.Linux64 1CD T

UVA The Tower of Babylon

The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story: The babylonians

Codeforces Gym 100269 Dwarf Tower (最短路)

题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game named "Dwarf Tower". In this game there are n different items,which you can put on your dwarf character. Items are numbered from 1 to n. Vasya want

3-6-汉诺塔(Hanoi Tower)问题-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版

课本源码部分 第3章  栈和队列 - 汉诺塔(Hanoi Tower)问题 ——<数据结构>-严蔚敏.吴伟民版        源码使用说明  链接??? <数据结构-C语言版>(严蔚敏,吴伟民版)课本源码+习题集解析使用说明        课本源码合辑  链接??? <数据结构>课本源码合辑        习题集全解析  链接??? <数据结构题集>习题解析合辑        本源码引入的文件  链接? 无外链        相关测试数据下载  链接? 无数

HDOJ题目4939 Stupid Tower Defense(dp)

Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1759    Accepted Submission(s): 498 Problem Description FSF is addicted to a stupid tower defense game. The goal of tower