当前位置:网站首页>7-7 solving mode problems
7-7 solving mode problems
2022-06-24 23:31:00 【White -】
7-7 Solve the mode problem
Given to contain n Multiple sets of elements S, Each element in S The number of occurrences in is called the multiplicity of the element . Multiple sets S The element with the largest multiplicity is called mode . for example ,S={1,2,2,2,3,5}. Multiple sets S What is the mode 2, Its multiplicity is 3. For a given by n A multiple set of natural numbers S, Calculation S Mode and multiplicity of . If there are multiple modes , Please output the smallest one .
Input format :
Number of input data 1 Rows are multiple sets S The number of elements in n(n<1000); Second line input n Up to 5 A natural number of digits .
14
1 2 2 2 3 3 5 6 6 5 6 2 7 6
Output format :
The second of the output data 1 OK, give me a few , The first 2 A row is a multiplicity .
2 4
Code :
#include <stdio.h>
#include <stdlib.h>
int n;
int a[10100];
int temp[10100];
int min=9999;
int mintime=0;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
int x=a[i];
temp[x]++;
if(temp[x]>mintime)
{
mintime=temp[x];
min=x;
}
else if(temp[x]==mintime&&x<min)
min=x;
}
printf("%d %d",min,mintime);
return 0;
}
202206222116 3、 ... and
边栏推荐
- 当初吃土建起来的“中台”,现在为啥不香了?
- QT to place the form in the lower right corner of the desktop
- Laravel user authorization
- Hydropower project construction scheme based on 3D GIS Development
- HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
- 372. 棋盘覆盖
- OpenSSL SSL_read: Connection was reset, errno 10054
- 7-2 后序+中序序列构造二叉树
- Listen to the markdown file and hot update next JS page
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses exp function and coef function to obtain the corresponding odds rat
猜你喜欢

Concurrent shared model management

7-7 数字三角形

伪原创智能改写api百度-收录良好

Detailed explanation of online group chat and dating platform project (servlet implementation)

企业数据防泄露解决方案分享

Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity

Jetpack Compose 最新进展

idea创建模块提示已存在

Still using simpledateformat for time formatting? Be careful of project collapse

【js】-【数组应用】-学习笔记
随机推荐
7-2 求解买股票问题
UNION ALL UNION FULL JOIN
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
OpenSSL SSL_ read: Connection was reset, errno 10054
7-7 数字三角形
throttle-debounce.js:一个小型的防抖节流函数库
Idea creation module prompt already exists
2021-2022 China's financial digitalization "new" insight Industry Research Report
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
Selective sort method
Main cause of EMI - mold current
Design and practice of vivo server monitoring architecture
379. hide and seek
7-6 铺设油井管道
257. detention of offenders
Hyperledger Fabric 2. X dynamic update smart contract
MySQL semi sync replication
Bubble sort
Record the range of data that MySQL update will lock