Lucky Year

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

My Answer Code:

/*
	Author:Albert Tesla Wizard
	Time:2021/3/29 20:56
*/
#include<bits/stdc++.h>
using namespace std;
int Pow(int n)
{
    
    
    int ans=1;
    while(n--)ans*=10;
    return ans;
}
void solve(int n)
{
    
    
    string s=to_string(n);
    int len=s.length();
    int first=s[0]-'0';
    cout<<(first+1)*Pow(len-1)-n<<'\n';
}
int main()
{
    
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    solve(n);
    return 0;
}


猜你喜欢

转载自blog.csdn.net/AlberTesla/article/details/115311102