Digit Count
- 比赛主页
- 我的提交
时间限制:C/C++ 5秒,其他语言10秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
Dr. Orooji’s children have played Tetris but are not willing to help Dr. O with a related problem.
Dr. O’s children don’t realize that Dr. O is lucky to have access to 100+ great problem solvers and
great programmers today!
Given a range (in the form of two integers) and a digit (0-9), you are to count how many
occurrences of the digit there are in the given range.
输入描述:
There is only one input line; it provides the range and the digit. Each integer for the range will be between 1000 and 9999 (inclusive) and the digit will be between 0 and 9 (inclusive). Assume the first integer for the range is not greater than the second integer for the range.
输出描述:
Print the number of occurrences of the digit in the given range.
示例1
输入
复制文章来源:https://www.toymoban.com/news/detail-420749.html
1000 1000 0
输出
复制
3
示例2
输入
复制
1000 1001 0
输出
复制
5
示例3
输入
复制
8996 9004 5
输出
复制
0
示例4
输入
复制
9800 9900 5
输出
复制文章来源地址https://www.toymoban.com/news/detail-420749.html
20
#include<iostream>
#include<set>
#include<cstring>
int solve(int x,int k){
int sum=0;
int a,b,c,d;
a=x/1000;
if(a==k) sum++;
b=(x-a*1000)/100;
if(b==k) sum++;
d=x%10;
if(d==k) sum++;
c=(x%100-d)/10;
if(c==k) sum++;
return sum;
}
using namespace std;
int main(){
int a,b;
int k;
cin>>a>>b>>k;
int res=0;
for(int i=a;i<=b;i++){
res+=solve(i, k);
}
cout<<res;
}
到了这里,关于Digit Count的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!