赞
踩
A. Lucky Year
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
4
output
1
input
201
output
99
input
4000
output
1000
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#define INF 2100000000
#define LL long long
#define clr(x) memset(x, 0, sizeof(x))
#define ms(a, x) memset(x, a, sizeof(x))
using namespace std;
const int maxn = 11;
LL n,ans;
LL a[maxn];
template <class T> inline void read(T &x) {
int flag = 1; x = 0;
char ch = (char)getchar();
while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = (char)getchar(); }
while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = (char)getchar(); }
x *= flag;
}
int main() {
read(n); a[0] = n;
for(int i = 1; i <= 10; i++) a[i] = a[0]%10, a[0] /= 10;
for(int i = 10; i >= 1; i--)
if(!a[i]) continue;
else {
ans = a[i]+1;
for(int j = 1; j < i; j++) ans *= 10;
break;
}
printf("%I64d",ans-n);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。