安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

描述试计算在区间 1 到 n的所有整数中数字x0≤x≤9共出现了多少次?例如在 1到11中即在 1234567891011 中数字 1 出现了 4 次。输入描述2个整数nx之间用一个空格隔开。用c++做输出描述1个整数表示x出现的次数。用例输入 1 00010100 1用例输出 1 2用例输入 2 11111111 1用例输出 2 8

  • 日期: 2025-01-08
  • 标签: 社会

#include #include using namespace std;

int main() { string num; int x; cin >> num >> x; int count = 0; for (int i = 0; i < num.length(); i++) { if (num[i] - '0' == x) { count++; } } cout << count << endl; return 0; }

描述试计算在区间 1 到 n的所有整数中数字x0≤x≤9共出现了多少次?例如在 1到11中即在 1234567891011 中数字 1 出现了 4 次。输入描述2个整数nx之间用一个空格隔开。用c++做输出描述1个整数表示x出现的次数。用例输入 1 00010100 1用例输出 1 2用例输入 2 11111111 1用例输出 2 8

原文地址: https://www.cveoy.top/t/topic/i93V 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: 档案管理岗位自我评价
  • 下一篇: !DOCTYPE htmlhtml lang=enhead meta charset=utf-8 meta name=viewport content=width=device-width initial-scale=1 title学生管理系统V11title !-- 图标 -- link rel=stylesheet href=pluginsfontawesome-

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2