codeforces——808A——Lucky Year
2017-05-29 08:35
253 查看
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 wholelucky years. Year is considered
lucky if it has no more than
1 non-zero digit in its number. So years 100, 40000, 5 arelucky 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 nextlucky 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
Output
Input
Output
Input
Output
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
问大于所给数字的下一个仅有一个非0的数字与所给数字的差
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 wholelucky years. Year is considered
lucky if it has no more than
1 non-zero digit in its number. So years 100, 40000, 5 arelucky 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 nextlucky 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
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
问大于所给数字的下一个仅有一个非0的数字与所给数字的差
#include<iostream> #include<algorithm> #include<stdio.h> #include<cstring> #include<cmath> #include<map> using namespace std; long long func1(int n);//原本是使用了pow()函数,但是提交时出现了问题,cf显示第二组数据输出98,但是我的测试是输出了99,很奇怪。自己写了个函数就过了。 int main() { int n; while(cin>>n!=NULL) { char s[20]; sprintf(s,"%d",n); int n2=strlen(s); cout<<(n/func1(n2-1)+1)*func1(n2-1)-n<<endl; } return 0; } long long func1(int n) { long long ans=1; while(n--) ans*=10; return ans; }
相关文章推荐
- 【Codeforces 808 A. Lucky Year】
- CodeForces 808A——Lucky Year——思维,模拟
- 【codeforces 808】B.Average Sleep Time
- 【codeforces 808】C.Tea Party(贪心)
- 【Codeforces 808 A. Straight «A»】
- 【Codeforces 808 B. Summer sell-off】
- 【Codeforces 808 B. Average Sleep Time】+ 前缀和
- codecodefor 808A——Lucky Year
- codeforces 808B——Average Sleep Time
- 【Codeforces 808 C. Tea Party】+ sort
- 【Codeforces 808A】【模拟】Lucky Year 题解
- 【Codeforces 808 D. Array Division】+ 二分
- Codeforces 808B——Average Sleep Time——思维
- CodeForces - 489F Special Matrices(DP)
- CodeForces 166'E
- CodeForces 448D Multiplication Table
- CodeForces 731E Funny Game
- Codeforces 834C The Meaningless Game【思维】
- CodeForces 374 B.Inna and Nine(组合数学)
- 【Codeforces】 489E Hiking