最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#278(Div.2)-A.GigaTower_html/css

来源:动视网 责编:小采 时间:2020-11-27 15:58:44
文档

CodeforcesRound#278(Div.2)-A.GigaTower_html/css

CodeforcesRound#278(Div.2)-A.GigaTower_html/css_WEB-ITnose:Giga Tower time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Giga Tower is the tallest and deepest building in Cyberland. There are 17777777777 floors, numbe
推荐度:
导读CodeforcesRound#278(Div.2)-A.GigaTower_html/css_WEB-ITnose:Giga Tower time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Giga Tower is the tallest and deepest building in Cyberland. There are 17777777777 floors, numbe


Giga Tower

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Giga Tower is the tallest and deepest building in Cyberland. There are 17?777?777?777 floors, numbered from ?-?8?888?888?888 to 8?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 all lucky while42,??-?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 test(s)

input

179

output

input

-1

output

input

18

output

10

Note

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.






题目大意:给一个数n,加上k之后,使得n中包含数字8. 求这样的最小的正整数k.



解题思路:其实本题的最大的k也就是16(n == -8时),直接在这里面暴力查找,然后每个都判断是否含有8即可。不过要注意,在判断的时候,如果是直接取模的话,则要注意 -8 % 10 == -8.




AC代码:

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x7ffffffflong long a;int check(long long x){ int flag = 0; while(x){ int f = x%10; if(abs(f) == 8){ //注意是abs(f) flag = 1; break; } x /= 10; } 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;}

文档

CodeforcesRound#278(Div.2)-A.GigaTower_html/css

CodeforcesRound#278(Div.2)-A.GigaTower_html/css_WEB-ITnose:Giga Tower time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Giga Tower is the tallest and deepest building in Cyberland. There are 17777777777 floors, numbe
推荐度:
标签: code div ht
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top