2550: 记数问题

 2550: 记数问题

Time Limit: 10000MS Memory Limit: 131072KB
Total Submit: 37 Accepted: 22 Page View: 30
Submit  Status  Discuss
 

试计算在区间 1 n 的所有整数中,数字 x(0 ≤ x ≤ 9)共出现了多少次?例如, 1 11 ,即在 1234567891011 ,数字 1 出现了 4 次。

 

输入共 1 行,包含 2 个整数 nx,之间用一个空格隔开

 

输出共 1 行,包含一个整数,表示 x 出现的次数。

对于 100%的数据,1 n  1,000,0000  x  9

一个很心累的题,我花了近两个小时在计算公式,还区分了0和其他数字的不同,结果。。。。。。。。。。。。只需要一轮循环就可以了,因为最大也就1000000,一轮循环不会超时的,所以直接把每个数字拿来进行比对累加就行。

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int n,m,ans=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        int a=i;
        for(int j=0;a>0;j++)
        {
            int x=a%10;
            if(x==m)
                ans++;
            a/=10;
        }
    }
    printf("%d\n",ans);
    return 0;
}


D:\anac\py39\python.exe D:/anac/project/222.py D:\anac\project\222.py:182: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class VideoAnalysisThread(QThread): D:\anac\project\222.py:446: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class TrafficMap3D(gl.GLViewWidget): D:\anac\project\222.py:588: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class LoginWindow(QWidget): D:\anac\project\222.py:847: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class RegisterWindow(QWidget): D:\anac\project\222.py:1097: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class MainWindow(QMainWindow): D:\anac\project\222.py:2498: DeprecationWarning: sipPyTypeDict() is deprecated, the extension module should use sipPyTypeDictRef() instead class MainApp(QMainWindow): Traceback (most recent call last): File "D:\anac\project\222.py", line 2550, in <module> main_app = MainApp() File "D:\anac\project\222.py", line 2517, in __init__ self.main_window = MainWindow() File "D:\anac\project\222.py", line 1132, in __init__ self.create_analysis_page() File "D:\anac\project\222.py", line 1846, in create_analysis_page tab_widget.addTab(self.create_vehicle_tab(), "车辆析") File "D:\anac\project\222.py", line 2080, in create_vehicle_tab axis_y.setRange(0, max(values) * 1.2) ValueError: max() arg is an empty sequence Process finished with exit code 1
最新发布
06-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值