B. Weird Rounding
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

思路:

  dfs~~~~;

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; int n,k,len,ans=0x7fffffff,p; char ch[]; bool if_[]; bool check()
{
int bzero=;
bool zero=true;
long long int pos=;
for(int i=;i<=len;i++)
{
if(if_[i]) continue;
if(zero)
{
if(ch[i]=='') bzero++;
else
{
zero=false;
pos=pos*+ch[i]-'';
}
}
else pos=pos*+ch[i]-'';
}
if(bzero==&&pos==) return true;
if(bzero>) return false;
if(pos%p==) return true;
return false;
} void dfs(int step,int ci)
{
if(step>=ans) return ;
if(check())
{
ans=step;
return ;
}
for(int i=ci+;i<=len;i++)
{
if(!if_[i])
{
if_[i]=true;
dfs(step+,i);
if_[i]=false;
}
}
} int main()
{
cin>>ch+;
cin>>k;
p=;
for(int i=;i<=k;i++) p=p*;
len=strlen(ch+);
dfs(,);
cout<<ans;
return ;
}

最新文章

  1. unity3d导出到IOS程序下 集成unity3dAR功能
  2. css的三种样式
  3. 关于C语言的问卷调查
  4. u3d_shader_surface_shader_6
  5. php 中的常量
  6. Android Studio 导入so
  7. Skrollr.js -- 使用Skrollr创建视差滚动效果页面
  8. [设计模式]&lt;&lt;设计模式之禅&gt;&gt;工厂方法模式
  9. HW5.2
  10. 彻底理解Gradle的任务
  11. Linux技术修复
  12. mysql的limit经典用法及优化
  13. mongodb batchInsert
  14. C++ Primer之 十二章 类
  15. red hat Linux 使用CentOS yum源更新
  16. Dom编程(三)
  17. 课程作业02(关于Java的几点讨论)
  18. Unity使用UGUI进行VR游戏的界面开发
  19. [Swift]LeetCode835. 图像重叠 | Image Overlap
  20. 【原创】大叔问题定位分享(32)mysql故障恢复

热门文章

  1. k8s基于canel的网络策略
  2. LeetCode939
  3. angular4使用代理
  4. 《流畅的python》读书笔记,第一章:python数据模型
  5. 逃离迷宫 HDU - 1728(bfs)
  6. Linux下查看USB设备信息
  7. BZOJ 2465: [中山市选2009]小球
  8. Android之高效率截图
  9. 学习boundingRectWithSize:options:attributes:context:计算文本尺寸
  10. Selenium WebDriver-判断页面中某一元素是否可操作