当前位置:网站首页>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
边栏推荐
猜你喜欢

【js】-【数组应用】-学习笔记

RT-thread使用rt-kprintf

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan

Huawei machine learning service speech recognition function enables applications to paint "sound" and color

【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化

SimpleDateFormat 格式化和解析日期的具体类

一文理解OpenStack网络

Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk

Actipro WPF Controls 2022.1.2

当初吃土建起来的“中台”,现在为啥不香了?
随机推荐
冒泡排序
libnum库简单使用(进制字符串转换)
7-7 数字三角形
372. 棋盘覆盖
Basic data type
(Smooth)ScrollToPosition doesn't work properly with RecyclerView
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
Yyds dry goods counting uses xshell to implement agent function
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉
安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX
Tomorrow is the PMP Exam (June 25). Have you understood all this?
No main manifest attribute in jar
[JS] - [array, Stack, queue, Link List basis] - Notes
Laravel scheduled task
7-2 后序+中序序列构造二叉树
HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
golang convert map to json string
二分查找数组下标
六大行数据治理现状盘点:治理架构、数据标准与数据中台(2022.04)
Simpledateformat concrete classes for formatting and parsing dates