779-B

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, ifk = 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 0001 ≤ 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.

思路:这道题确切的来说有三种情况:
1:数字除去第一位后的长度小于k值
2:删去0之外的数所剩长度依旧不小于k
3:删去0之外的数所剩长度小于k
由于忘记考虑第三种情况,wrong了一发。。。
代码:
#include
#include
#include
#include
using namespace std;
char s[15];
int main()
{

    while(~scanf("%s",s))
    {
        int n;
        scanf("%d",&n);
        int p=strlen(s);
        int sum=0;
        if(p>n)
        {
            for(int i=p-1;i>0&&n;i--)
            {
                if(s[i]=='0')
                    n--;
                else
                    sum++;
            }
            if(!n)
            printf("%d\n",sum);//第二种情况。

            else//第三种情况
            {
                for(int i=0;i


你可能感兴趣的:(ACM竞赛,ACM的进程)