天天看點

codeforces 779B Weird Rounding

​​點選打開連結​​

B. Weird Rounding

time limit per test

memory limit per test

input

output

10k.

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.

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

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

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.

今天小賽的第三題,竟然錯了12次,距結束還有3分鐘時對了,我也不是很清楚,很迷。

#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    long long n,k;
    scanf("%I64d%I64d",&n,&k);
    if(k==0)
    {
        printf("0\n");
        return 0;
    }
    int ok=0;
    int s=0,m=0,w;
    while(n>=10)
    {
        w=n%10;
        n=n/10;
        if(w==0)
            s++;
        else
            m++;
        if(s==k)
        {
            ok=1;
            break;
        }
    }
    if(ok)
        printf("%d\n",m);
    else
    {
        printf("%d\n",s+m);
    }
    return 0;
}