您的位置:首页 > 其它

【Codeforces 808A】【模拟】Lucky Year 题解

2017-05-30 17:22 211 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: