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.
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
4
1
201
99
4000
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;
}