赞
踩
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.
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
4
1
201
99
4000
1000
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
写的复杂了点。。。
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- const int maxn = 100+7;
- int t;
- ll n;
-
- ll Find()
- {
- int c[11], cas = 0;
- ll k = n;
- memset(c, 0, sizeof(c));
- while(k)
- {
- c[cas++] = k%10;
- k /= 10;
- }
- int m = 0;
- ll sum = 0, s = 1;
- if(cas == 1) return 1;
- for(int i = 0; i < cas - 1; i++)
- {
- if(c[i] != 0)
- {
- sum += (10 - c[i])*s;
- c[i + 1] += 1;
- }
- else m = 0;
- s*=10;
- }
- if(sum == 0) return s;
- else return sum;
- }
-
-
- int main()
- {
- scanf("%d",&n);
- printf("%lld\n", Find());
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。