惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
V
V2EX
Jina AI
Jina AI
爱范儿
爱范儿
M
MIT News - Artificial intelligence
量子位
L
LangChain Blog
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
腾讯CDC
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
AOJ 1035.有魔力的数字|OhYee 博客
2017-11-27 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

{% fold 点击显/隐题目 %}

众所周知,蕊蕊是一个非常喜欢数学的人。而她特别喜欢能被10k整除的数字,现在给定一个数字n和一个数字k。现在请你帮帮蕊蕊算一算至少需要删除掉多少数字才能使数字n变成10k的倍数。数据保证一定有解,并且n没有多余的前导0 。注意:00不是一个合法的数字。需要多删除一位变成0,才能被10k 整除。

一行有两个数字n和k, (0 ≤ n ≤ 2 000 000 000, 1 ≤ k ≤ 9)

一个整数,代表至少需要删除多少个数字才能使数字n被10^k 整除

样例一: 30020 3 样例二: 100 9 样例三: 10203049 2

样例一: 1 样例二: 2 样例三: 3

{% endfold %}

题解

检查后k位是否全是0,如果不是就删去非0的字符,然后继续检查

如过删到不足k位,就直接输出位数,否则输出删掉的字符数

代码

{% fold 点击显/隐代码 %}```cpp 有魔力的数字 https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份

#include
#include
#include
#include
#include
using namespace std;

const int maxn = 15;
char s[maxn];
int k;

void de(int pos)
{
int len = strlen(s);
for(int i=pos; i<len;++i)
s[i] = s[i+1];

}

int main()
{
//freopen("in.txt","r",stdin);

scanf("%s%d",s,&k);
int len = strlen(s);
int ans = 0;
bool flag = false;

while(len >= k)
{
    //printf("%s\n",s);
    flag = true;
    for(int i=0; i<k; ++i)
    {
        //printf("s[%d]=%c\n",len-1-i,s[len-1-i]);
        if(s[len-1-i]!='0')
        {
            ++ans;
            de(len-1-i);
            flag = false;
            break;
        }
    }
    //printf("flag:%d\n",flag);

    if(flag)
        break;
    len = strlen(s);
}
if(flag)
    printf("%d\n",ans);
else
    printf("%d\n",ans+len-1);

return 0;

}

{% endfold %}