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
给你一个数,如果这个数各位上有且仅有一个非零的数,那么这个数是符合条件的。给你一个数让你判断这个数的下一个符合条件的数是哪一个,并输出这俩数的差值。
解:
就是求这个数是几位数么,如:4098,是四位数,下一个数一定是5000咯。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int len=log10(n); //求第一个数后有几位数
//printf("%d\n",len);
int tem=n;
for(int i=0;i<len;i++)
tem/=10;
tem++;
for(int i=0;i<len;i++)
tem*=10;
printf("%d\n",tem-n);
}
return 0;
}