跳到正文

题解

B2096 直方图 题解

Zhoumy约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
获赞
2
题目
B2096

版本

  1. v1当前

我们可以直接输入,枚举哪个数是最大的数,然后在数组里把每个数的数量加起来,最后依次输出。

C++
#include<bits/stdc++.h>
using namespace std;
int a[100005],n,c,Fmax;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c;
		a[c]++;//每个数字的数量
		Fmax=max(Fmax,c);//找最大的数
	}
	for(int i=0/*从0开始*/;i<=Fmax;i++)cout<<a[i]<<endl;//输出
	return 0;
}
原文