A - Giga Tower(488A - Giga Tower)

  1. 488A - Giga Tower
Examples
input
Copy
179
output
Copy
1
input
Copy
-1
output
Copy
9
input
Copy
18
output
Copy
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.



  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int f(long n){
  4. int i;long x;
  5.  
  6. if(n<0) x=abs(n);
  7. bool b=false;
  8. if(n>=0)while(n>0){
  9. i = n%10;
  10. if(i==8)
  11. { b= true ;break;}
  12. n=n/10;
  13. }
  14. else
  15. while(n<0){
  16. i = n%10;
  17. if(i==-8)
  18. { b= true ;break;}
  19. n=n/10;
  20. }
  21.  
  22. if(b) return 1;
  23. else return 0;
  24. }
  25.  
  26. int main(){
  27.  
  28. long n,cnt=0;
  29. string ch;
  30. cin>>n;
  31. {
  32. while(1){
  33. n++;
  34.  
  35. cnt++;
  36. if(f(n)==1) {cout<<cnt; break;}
  37. }}
  38.  
  39. return 0;
  40. }

Comments

Popular posts from this blog

Codeforce Problem 1703A. YES or YES?

Aptitude test assistant programmer 2018

1041A. Heist solution