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.
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.
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).
30020 3
1
100 9
2
10203049 2
3
source:点击打开链接
题意:给你一个数你,一个数k,问删去n中的多少个数字后能被10的k次方整除。
代码:
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
string s;
int t;
while(cin>>s>>t)
{
int ans=0;
int n = s.length();
for (int i = 0; i < n; i++)
{
if (s[i] == '0')
ans++;
}
if (ans >= t)
{
int f = 0;
int num0 = 0;
for (int i = n - 1; i >= 0; i--)
{
if (s[i] == '0')
{
num0++;
if (num0 == t)
break;
}
else
{
f++;
}
}
printf("%d\n",f);
}
else
printf("%d\n",n-1);
}
return 0;
}