Problem A

╰+哭是因爲堅強的太久メ 2022-06-13 20:57 268阅读 0赞

Problem A

Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 504 Accepted Submission(s) : 99

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

请统计给定某个范围[L,R](1<=L<R<=10000)的所有整数中,出现数字M(1<=M<=9)的总次数。

Input

一行输入三个整数L、R、M,中间以空格隔开。(有多个测试用例)

Output

输出[L,R]之间所有整数中出现M的次数总和。

Sample Input

  1. 2 22 2

Sample Output

  1. 6
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. using namespace std;
  6. int main()
  7. {
  8. int l,r,m;
  9. int a[10];
  10. while(~scanf("%d %d %d",&l,&r,&m))
  11. {
  12. memset(a,0,sizeof(a));
  13. for(int i=l;i<=r;i++)
  14. {
  15. int j=i;
  16. while(j)
  17. {
  18. int x=j%10;
  19. a[x]++;
  20. j=j/10;
  21. }
  22. }
  23. printf("%d\n",a[m]);
  24. }
  25. return 0;
  26. }

发表评论

表情:
评论列表 (有 0 条评论,268人围观)

还没有评论,来说两句吧...

相关阅读

    相关 A+B Problem(V)

    描述 做了A+B Problem之后,Yougth感觉太简单了,于是他想让你求出两个数反转后相加的值。帮帮他吧 输入 有多组测试数据。每组包括两个数m和n,数据保证int

    相关 1000 A+B problem

    复习不知道该复习什么了,也快暑假找工作了,转眼就大四了,总得找点事做,刷题吧,从北大oj里面一道一道的来吧,不知道自己能刷到哪里。 Description Calculat