当前位置:   article > 正文

【Codeforces 808A】【模拟】Lucky Year 题解_lucky?题解codeforce

lucky?题解codeforce

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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/72379
推荐阅读
相关标签
  

闽ICP备14008679号