当前位置:   article > 正文

CodeForces - 808A. Lucky Year_apart from having lots of holidays throughout the

apart from having lots of holidays throughout the year, residents of berland
A. Lucky Year
time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output

Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.

You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.

Input

The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.

Output

Output amount of years from the current year to the next lucky one.

Examples
input
Copy
4
output
1
input
Copy
201
output
99
input
Copy
4000
output
1000
Note

In the first example next lucky year is 5. In the second one — 300. In the third — 5000.


   写的复杂了点。。。

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int maxn = 100+7;
  5. int t;
  6. ll n;
  7. ll Find()
  8. {
  9. int c[11], cas = 0;
  10. ll k = n;
  11. memset(c, 0, sizeof(c));
  12. while(k)
  13. {
  14. c[cas++] = k%10;
  15. k /= 10;
  16. }
  17. int m = 0;
  18. ll sum = 0, s = 1;
  19. if(cas == 1) return 1;
  20. for(int i = 0; i < cas - 1; i++)
  21. {
  22. if(c[i] != 0)
  23. {
  24. sum += (10 - c[i])*s;
  25. c[i + 1] += 1;
  26. }
  27. else m = 0;
  28. s*=10;
  29. }
  30. if(sum == 0) return s;
  31. else return sum;
  32. }
  33. int main()
  34. {
  35. scanf("%d",&n);
  36. printf("%lld\n", Find());
  37. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/75823
推荐阅读
相关标签
  

闽ICP备14008679号