CodeForces
来源:互联网 发布:淘宝的内部优惠微信号 编辑:程序博客网 时间:2024/06/16 13:38
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000.
Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).
It is guaranteed that the answer exists.
Input
The only line of the input contains two integer numbers n and k (0 ≤ n ≤ 2 000 000 000, 1 ≤ k ≤ 9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.
Output
Print w — the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).
Example
Input
30020 3
Output
1
Input
100 9
Output
2
Input
10203049 2
Output
3
Note
In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number.
从后向前找有几个0不足就输出字符串-1
否则输出不是0
#include<iostream>#include<cmath>#include<queue>#include<algorithm>#include<cstdio>#include<stack>#include<string>using namespace std;typedef long long ll;int biaoji[1000001];int main(){ string q; int k; cin >> q >> k; int y = k; int yy = 0; for (int a = q.size()-1; a >= 0; a--) { if (q[a] == '0')y--; else yy++; if (!y)break; } if (y) { cout << q.size() - 1; return 0; } cout << yy;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- C++中两个类相互引用的解决办法
- Nginx服务器下ThinkPHP5访问出现404以及URL隐藏index.php
- 负载均衡以及四层和七层负载均衡的区别
- 正则表达式-匹配IP、域名
- Java数据类型
- CodeForces
- 64位centos7 编译 32位文件出错
- frame、bounds与center属性
- 取近似值
- spark 2.1 reduce
- win10磁盘占用100%
- [bigdata-077] maven+mybatis+mysql 数据库 mybatis xml文件方式 示例
- Android-四种进程类型
- Nginx.conf 中的location 详解