首页 > 代码库 > codeforces 488A. 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 <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_JUDGE26 freopen("in.txt", "r", stdin);27 #endif // ONLINE_JUDGE28 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 else38 break;39 }40 printf("%I64d\n", cnt);41 }42 return 0;43 }
codeforces 488A. Giga Tower 解题报告
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。