cf 808 A
来源:互联网 发布:表白源码 编辑:程序博客网 时间:2024/05/22 00:21
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.
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.
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
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循环了。。。。
阅读全文
0 0
- cf 808 A
- CF#808 A. Lucky Year(水题)
- CF 2A Winner
- CF 128A Statues
- <cf>A. Exams
- CF 109A
- CF 111A
- CF 4A Watermelon
- CF 237A (Cash)
- CF 6 A - Triangle
- CF:96A.Football
- CF:208A. Dubstep
- CF:41A. Translation
- CF:59A. Word
- CF:43A. Football
- CF:78A. Haiku
- CF:A. Flipping Game
- CF 148 div1 A
- Java--玩四叶玫瑰
- JS实现单选、全选、反选
- python 爬取12306验证码
- Java网络编程——第八章 客户端Socket
- 《高频交易》边读边学
- cf 808 A
- 链表六双向循环链表
- 2016背包专题1010
- 【感想库】--生气---不管别人对错,我们都要把自己活的更好(206)
- 使用Lucene开发简单的站内新闻搜索引擎(环境的搭建)
- 1139: 神奇的fans
- hadoop系列之hive
- 2017计蒜之道 初赛第一场 阿里天池的新任务(简单)
- H2内存数据库