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
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
水题,发这个题的目的只有一个,因为比赛的时候居然wa了一下,错误让我 也很尴尬
先看代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int x;
int k=0;
int m=n;
while(n)
{
k++;
x=n%10;
n=n/10;
}
int sum=(x+1);
for(int i=1;i<k;i++)
sum*=10;
cout<<sum-m<<endl;
}
return 0;
}
第一发用了pow(10,k-1),错了,后来只好改为for循环了。。。。