Educational Codeforces Round 21 A. Lucky Year

 
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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
題意:給一個數n,目標數只有一個位爲非0,問當前數到下一個目標數距離之差爲多少
找到這個數位數n,然後從10^n不斷減小到比這個數大的10^(n-1)的數。輸出兩者之差即可。
人生第一篇博客啊。


#include <iostream>
#include <algorithm>
#include <cstdio>
typedef long long ll;
using namespace std;
bool isst(ll a){
    int b = 0;
    for(;a>0;a/=10)
        if(a%10!=0)
            b++;
    if(b>1)
        return false;
    return true;
}
int main()
{
    int highwei=0;
    int n,m;
    cin>>n;
    m=n;
    while(m){
        highwei++;
        m/=10;
    }
    ll hi=1,mi=1;
    while(highwei--) hi*=10;
    mi=hi/10;
    while(hi>n)
    {
        hi-=mi;
    }
    hi+=mi;
    cout<<hi-n<<endl;
    return 0;
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章