首页 > 代码库 > 第一次ACM比赛
第一次ACM比赛
在慌忙之中被通知第一次参加ACM比赛,虽然只是校内练习赛,但着实小紧张了一把,所以就卡壳在了第一题上,提交了好多次发现总是不对,刚开始编译错误,到测试数据不过,到最后也都没有写完。回来后思考了一下,算法的确错了,又试了几次,终于写完了。下附第一题
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 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.
The only line of input contains an integer a ( - 109 ≤ a ≤ 109).
Print the minimum b in a line.
#include<stdio.h>int mabs(int h){ if(h<0) h=-h; return (h);}int main(){ int i,m,n,j,a,b,c,t,s=1,h=0,o=0,k=0; scanf("%d",&a); for(i=0;i<16;i++) { a++; t=mabs(a); //printf("%d\n",t); for(s=1,k=0,o=0;k<10;k++) { s=s*10; h=t%s; //printf("%d\n",h); if(h==0.8*s) {o++; break; } t=t-h; //printf("%d\n",t); } if(o!=0) {printf("%d\n",i+1); break;} //printf("%d\n",o); }return 0;}
第一次ACM比赛