Digit Count

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

输入

复制

1000 1000 0

输出

复制

3

示例2

输入

复制

1000 1001 0

输出

复制

5

示例3

输入

复制

8996 9004 5

输出

复制

0

示例4

输入

复制

9800 9900 5

输出

复制

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值