CodeForces - 808A Lucky Year

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 808A Lucky Year相关的知识,希望对你有一定的参考价值。

A. Lucky Year
time limit per test1 second
memory limit per test256 megabytes

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.

问题链接CodeForces - 808A Lucky Year
问题简述:给定一个数,求比它大只有1位非0数字的数与原数的差是多少?
问题分析:(略)
AC的C++语言程序如下:

/* CodeForces - 808A Lucky Year */

#include <stdio.h>

int main()

    int n, cnt = 0;

    scanf("%d", &n);

    int t = n;
    while (t) t /= 10, cnt++;
    int ans = 1;
    for (int i = 1; i < cnt; i++)
        ans *= 10;

    printf("%d\\n", ans - n % ans);

    return 0;

以上是关于CodeForces - 808A Lucky Year的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 808A

『题解』Codeforces121A Lucky Sum

Lucky Numbers (easy) CodeForces - 96B

CodeForces E. Lucky Array 幸运数列

@codeforces - 1096G@ Lucky Tickets

codeforces 110E Lucky Tree