Description

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 by10k. 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).

Examples
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.

题意:删除第一个数字某些位数,可以使得被10K整除,求最少次数

解法:倒着遍历记录0的个数,以及不为0的个数,如果0的个数等于K,跳出遍历,输出不为0的个数,还有始终达不到K的情况,因为题目说一定有解,那么最后留下来的只有0,也就是输出数字的长度-1

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string s;
ll num=;
ll ans=;
ll k;
cin>>s>>k;
for(int i=s.size()-; i>=; i--)
{
if(s[i]=='')
{
num++;
if(num>=k)
{
break;
}
} else
{
ans++;
}
}
if(num==k)
{
cout<<ans<<endl;
}
else
{
cout<<s.size()-<<endl;
}
return ;
}

最新文章

  1. 负margin的移位参考线
  2. 初学cocos2dx-3.x之使用Scale9Sprite时的配置问题
  3. 蘑菇街iOS客户端应用源码
  4. 关于JS中变量的作用域-实例
  5. Uploadify帮助文档
  6. hdu 3518 Boring counting 后缀数组LCP
  7. Hibernate学习笔记--环境搭建及运行
  8. iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority【转】
  9. editplus配置详:
  10. linux下java调用.so动态库方法2: JNA
  11. Android登陆界面实现-支持输入框清楚和震动效果功能
  12. JavaEEB2C网上商城前端系统
  13. 企业微信开发之向员工付款(C#)
  14. IDEA集成git方法
  15. iOS重写和成员变量访问权限
  16. OSGI企业应用开发(十二)OSGI Web应用开发(一)
  17. Eclipse/MyEclipse上配置Spring环境
  18. magento建立多语言网站
  19. 配置sql server 2000以允许远程访问
  20. MapReduce模式MapReduce patterns

热门文章

  1. PHP琐碎学习
  2. 键盘HOOK显示按键信息
  3. Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP
  4. Hibernate exception
  5. 搭建java运行环境
  6. #import @import #include
  7. spring-jar包详解整理(大合集)
  8. 使用RAID进行磁盘管理
  9. java邮件发送(含附件)
  10. 一步一步学Silverlight 2系列(21):如何在Silverlight中调用JavaScript