【Codeforces 808A】【模拟】Lucky Year 题解
2017-05-30 17:22
211 查看
A. Lucky Year
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <set> #include <queue> #include <algorithm> #include <vector> #include <cstdlib> #include <cmath> #include <ctime> #include <stack> #define INF 2100000000 #define LL long long #define clr(x) memset(x, 0, sizeof(x)) #define ms(a, x) memset(x, a, sizeof(x)) using namespace std; const int maxn = 11; LL n,ans; LL a[maxn]; template <class T> inline void read(T &x) { int flag = 1; x = 0; char ch = (char)getchar(); while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = (char)getchar(); } while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = (char)getchar(); } x *= flag; } int main() { read(n); a[0] = n; for(int i = 1; i <= 10; i++) a[i] = a[0]%10, a[0] /= 10; for(int i = 10; i >= 1; i--) if(!a[i]) continue; else { ans = a[i]+1; for(int j = 1; j < i; j++) ans *= 10; break; } printf("%I64d",ans-n); return 0; }
相关文章推荐
- CodeForces 808A——Lucky Year——思维,模拟
- codeforces-#469A. I Wanna Be the Guy(模拟)
- CodeForces 339B Xenia and Ringroad(水题模拟)
- CodeForces 342B--模拟+贪心
- 【20150905】NOIP模拟套题01 day2 题解 & 总结
- CodeForces - 868B Race Against Time(模拟)
- Codeforces 10A-Power Consumption Calculation(模拟)
- Codeforces 518C Anya and Smartphone【思维+模拟】
- Codeforces,578C,贪心出错,手工模拟“或”操作
- Codeforces 812A Sagheer and Crossroads[模拟]
- CodeForces - 148B Escape (模拟)
- 【NOIP2016提高A组模拟7.15】颜料大乱斗 题解+代码
- Codeforces 813C The Tag Game 题解
- Codeforces-697B-Barnicle(模拟)
- Codeforces 363A Soroban(算盘模拟)
- CodeForces 118C 【模拟】
- codeforces 2C Commentator problem (2) -- 模拟退火
- CodeForces - 548B Mike and Fun (模拟)
- Codeforces 876 D. Sorting the Coins 模拟
- CodeForces 546B - Soldier and Badges(模拟)