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 ;
}

Codeforces Round #402 (Div. 2) B的更多相关文章

  1. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  2. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  3. Codeforces Round #402 (Div. 2) A,B,C,D,E

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #402 (Div. 2) D. String Game

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces Round #402 (Div. 2) A B C sort D二分 (水)

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding

    暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...

  7. Codeforces Round #402 (Div. 2) 题解

    Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...

  8. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  9. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

随机推荐

  1. Ajax的简单实现

    Ajax的实现需要服务器端和客户端配合来实现 下面看服务器端的代码,也就是用php编写的一个后台脚本文件 <?php //设置页面内容,编码格式是utf8 header("Conten ...

  2. 设置GridCtrl中的Checkbox 为不可编辑

    m_Grid.SetCellType(index, 1, CGridCtrl::CellType_Check);   //设置第index行.第一列的单元格为类似CheckBox的模样    m_Gr ...

  3. SHOW PROCESSLIST Syntax

    https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html SHOW PROCESSLIST shows you which threa ...

  4. object equal

    package equals; public class EqualsTest { public static void main(String[] args) { Employee alice1 = ...

  5. group by where having 联合使用

    having子句与where有相似之处但也有区别,都是设定条件的语句.在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先执行.而where子句在查询过程中执行优 ...

  6. HDU 6109 数据分割 【并查集+set】 (2017"百度之星"程序设计大赛 - 初赛(A))

    数据分割 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. PrintWrite

    向文本输出流打印对象的格式化表示形式.此类实现在 PrintStream 中的所有 print 方法.它不包含用于写入原始字节的方法,对于这些字节,程序应该使用未编码的字节流进行写入. 与 Print ...

  8. activity四种状态

    finish()  使得activity死掉 activity 部分可见进入pause状态.全部不可见进入stop状态 .界面从死亡——运行(启动) MainAdctivity.onCreate.on ...

  9. iOS中城市定位功能的实现

    引入框架:CoreLocation .h文件 引入CoreLocation/CoreLocation.h @interface WeatherViewController :UIViewControl ...

  10. js运行机制及异步编程(一)

    相信大家在面试的过程中经常遇到查看执行顺序的问题,如setTimeout,promise,async await等等,各种组合,是不是感觉头都要晕掉了,其实这些问题最终还是考察大家对js的运行机制是否 ...