Codeforces Round #402 (Div. 2) B
Description
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 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.
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
In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number.
题意:删除第一个数字某些位数,可以使得被10K整除,求最少次数
解法:倒着遍历记录0的个数,以及不为0的个数,如果0的个数等于K,跳出遍历,输出不为0的个数,还有始终达不到K的情况,因为题目说一定有解,那么最后留下来的只有0,也就是输出数字的长度-1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string s;
ll num=;
ll ans=;
ll k;
cin>>s>>k;
for(int i=s.size()-; i>=; i--)
{
if(s[i]=='')
{
num++;
if(num>=k)
{
break;
}
} else
{
ans++;
}
}
if(num==k)
{
cout<<ans<<endl;
}
else
{
cout<<s.size()-<<endl;
}
return ;
}
最新文章
- 负margin的移位参考线
- 初学cocos2dx-3.x之使用Scale9Sprite时的配置问题
- 蘑菇街iOS客户端应用源码
- 关于JS中变量的作用域-实例
- Uploadify帮助文档
- hdu 3518 Boring counting 后缀数组LCP
- Hibernate学习笔记--环境搭建及运行
- iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority【转】
- editplus配置详:
- linux下java调用.so动态库方法2: JNA
- Android登陆界面实现-支持输入框清楚和震动效果功能
- JavaEEB2C网上商城前端系统
- 企业微信开发之向员工付款(C#)
- IDEA集成git方法
- iOS重写和成员变量访问权限
- OSGI企业应用开发(十二)OSGI Web应用开发(一)
- Eclipse/MyEclipse上配置Spring环境
- magento建立多语言网站
- 配置sql server 2000以允许远程访问
- MapReduce模式MapReduce patterns