博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF779B(round 402 div.2 B) Weird Rounding
阅读量:5323 次
发布时间:2019-06-14

本文共 2326 字,大约阅读时间需要 7 分钟。

题意:

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

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.

思路:

模拟,贪心。

实现:

1 #include 
2 #include
3 #include
4 using namespace std; 5 6 int main() 7 { 8 string s; 9 int t;10 cin >> s >> t;11 int n = s.length();12 int cnt = 0;13 for (int i = 0; i < n; i++)14 {15 if (s[i] == '0')16 cnt++;17 }18 if (cnt >= t)19 {20 int f = 0;21 int num0 = 0;22 for (int i = n - 1; i >= 0; i--)23 {24 if (s[i] == '0')25 {26 num0++;27 if (num0 == t)28 break;29 }30 else31 {32 f++;33 }34 }35 cout << f << endl;36 }37 else38 cout << n - 1 << endl;39 return 0;40 }

 

转载于:https://www.cnblogs.com/wangyiming/p/6445506.html

你可能感兴趣的文章
2018icpc徐州OnlineA Hard to prepare
查看>>
使用命令创建数据库和表
查看>>
【转】redo与undo
查看>>
安卓当中的线程和每秒刷一次
查看>>
wpf样式绑定 行为绑定 事件关联 路由事件实例
查看>>
TCL:表格(xls)中写入数据
查看>>
Oracle事务
查看>>
String类中的equals方法总结(转载)
查看>>
标识符
查看>>
一步步教你轻松学奇异值分解SVD降维算法
查看>>
内存地址对齐
查看>>
创新课程管理系统数据库设计心得
查看>>
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
[转载] redis 的两种持久化方式及原理
查看>>
MyBaits学习
查看>>
管道,数据共享,进程池
查看>>
[Cypress] Stub a Post Request for Successful Form Submission with Cypress
查看>>
SDUTOJ3754_黑白棋(纯模拟)
查看>>
php中的isset和empty的用法区别
查看>>
把word文档中的所有图片导出
查看>>