Skip to content

P1554 梦中的统计 #5

@RyanHe0

Description

@RyanHe0

梦中的统计

题目背景

Bessie 处于半梦半醒的状态。过了一会儿,她意识到她在数数,不能入睡。

题目描述

Bessie 的大脑反应灵敏,仿佛真实地看到了她数过的一个又一个数。她开始注意每一个数码($0 \ldots 9$):每一个数码在计数的过程中出现过多少次?

给出两个整数 $M$$N$,求在序列 $[M, M + 1, M + 2, \ldots, N - 1, N]$ 中每一个数码出现了多少次。

输入格式

$1$ 行: 两个用空格分开的整数 $M$$N$

输出格式

$1$ 行: 十个用空格分开的整数,分别表示数码 $0 \ldots 9$ 在序列中出现的次数。

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,ans[10]={0},tmp;
	scanf("%d %d",&n,&m);
	for (int i=n;i<=m;i++){
		tmp=i;
		
		while(tmp){
			ans[tmp%10]++;
			tmp/=10;
		}
	}
	for (int i=0;i<10;i++) printf("%d ",ans[i]);
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions