当前位置:网站首页>OJ 1284 记数问题
OJ 1284 记数问题
2022-07-28 05:26:00 【JETECHO】
描述
试计算在区间1到n的所有整数中,数字x(0≤x≤9)共出现了多少次?例如,在1到11中,即在1、2、3、4、5、6、7、8、9、10、11中,数字1出现了4次。
输入
每组输入数据共1行,包含2个整数n、x,之间用一个空格隔开。
数据规模:
对于100%的数据,1≤n≤1,000,000,0≤x≤9。
输出
每组输出共1行,包含一个整数,表示x出现的次数。
输入样例 1
11 1
输出样例 1
4
题目要求找出数字出现的次数,可以使用循环,从1到n检查,通过取余10和除以10来获取每一位,来判断是否为x
#include <iostream>
#include <string>
using namespace std;
int main()
{
long long x,n;
while(cin>>x>>n)
{
int cont=0;
for(int i=1;i<=x;i++)
{
int k=i;
while(k)
{
if(k%10==n)
cont++;
k/=10;
}
}
cout<<cont<<endl;
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
2022-07-17 Damon database installation
夹子套利/搬砖套利系统开发
气传导耳机哪个好、性价比最高的气传导耳机推荐
Pyppeteer is recognized to bypass detection
What is the best and most cost-effective open headset recommended
MFC uses the console to print program information
Five categories of IP addresses
Perl introductory learning (XI) file operation
OJ 1451 数字游戏
error: redefinition of ‘xxx‘
Find the network address and broadcast address of the host according to the IP address and subnet mask
开放式耳机有哪些、四款音质超好的气传导耳机推荐
2022-07-19 Damon database - instance creation and management
Filter
刷题记录----链表
Leetcode 刷题日记 剑指 Offer II 047. 二叉树剪枝
Leetcode 刷题日记 剑指 Offer II 048. 序列化与反序列化二叉树
1、 Ffmpeg record audio as PCM file
scrapy 命令
Problems of font modification and line spacing in word automatic directory






![[队列,栈的简单应用----包装机]](/img/bc/617b1eb35558c4f948018f593a1de5.jpg)


