当前位置:网站首页>OJ 1284 counting problem
OJ 1284 counting problem
2022-07-28 06:38:00 【JETECHO】
describe
Try to calculate in the interval 1 To n Of all integers , Numbers x(0≤x≤9) How many times have there been ? for example , stay 1 To 11 in , That is to say 1、2、3、4、5、6、7、8、9、10、11 in , Numbers 1 There is 4 Time .
Input
Each group of input data has a total of 1 That's ok , contain 2 It's an integer n、x, Separated by a space .
Data scale :
about 100% The data of ,1≤n≤1,000,000,0≤x≤9.
Output
Total output per group 1 That's ok , Contains an integer , Express x Number of occurrences .
sample input 1
11 1
sample output 1
4
The question requires finding out the number of times the number appears , You can use loops , from 1 To n Check , adopt Remainder 10 And divided by 10 To get every bit , To determine whether it is 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;
}
边栏推荐
猜你喜欢
随机推荐
气传导耳机哪个好、性价比最高的气传导耳机推荐
七夕送女朋友什么礼物好?不会送礼的男生速看!
战疫杯--我的账本
Relative path and absolute path
到底什么是Hash?(量化交易机器人系统开发)
【动态规划--买卖股票的最佳时期系列】
气传导蓝牙耳机什么牌子好、气传导耳机最好的品牌推荐
微信小程序自定义编译模式
[PTA----树的遍历]
Pyppeter drop-down selenium drop-down
2022年七夕礼物推荐!好看便宜又实用的礼物推荐
2022-06-07 VI. log implementation
做气传导耳机最好的是哪家、最好的气传导耳机盘点
gerapy 使用
空气传导耳机哪个牌子好、备受好评的气传导耳机推荐
[untitled]
OJ 1045 反转然后相加
2022-07-19 Damon database connection instance, execution script, system command
JSP should pass parameters to the background while realizing the file upload function
Five categories of IP addresses








