当前位置:网站首页>Sequence table - find main element
Sequence table - find main element
2022-06-13 00:48:00 【Feiyichai】
Examples of kingcraft : As efficient as possible , Find the main element
Because it is required to be as efficient as possible , So we use the time for space algorithm , Set up an auxiliary array , Its capacity is the maximum in the sequence , Count their appearance times , If it meets the requirements, output .
#include<stdio.h>
#define MAXSIZE 100
int main(){
// Find the main element
int a[] ={
0,3,3,3,3,7,5,5};
int temp[MAXSIZE];
int max=a[0];
int i;
for(i=0;i<9;i++){
// Find the maximum value of the sequence
if(max<a[i])
max=a[i];
}
printf("%d ",max);
for(i=0;i<max;i++){
// Auxiliary array timer initialization
temp[i]=0;
}
for(i=0;i<9;i++){
temp[a[i]]++;// Statistics
}
int t=0;
for(i=0;i<max;i++){
if(temp[i]>=n/2){
t=i;// Main element found
break;
}
}
if(t!=0)// Output main element
printf("%d",t);
}
边栏推荐
- Oceanbase is the leader in the magic quadrant of China's database in 2021
- 深度学习每周期的步数多少合适?
- 天津银行周传凯:从 0 到 1,我的分布式数据库落地经验谈
- MCU serial port interrupt and message receiving and sending processing -- judge and control the received information
- 单片机串口中断以及消息收发处理——对接受信息进行判断实现控制
- Hard (magnetic) disk (I)
- Build your own PE manually from winpe of ADK
- What is the difference between pytorch and tensorflow?
- Buuctf babyupload[gxyctf2019]
- 1. Google grpc framework source code analysis Hello World
猜你喜欢

MySQL lpad() and rpad() concatenate string functions with specified length

Stack overflow learning summary

Canvas game 2048 free map size

Canvas airplane game

Daily buckle exercise - conclusion

Maybe we can figure out the essence of the Internet after the dust falls

Penetration test summary

antdPro - ProTable 实现两个选择框联动效果

Cve-2021-24078 vulnerability analysis

Static analysis of malicious code
随机推荐
What is pytorch? Explain the basic concepts of pytorch
Kotlin 协程的四种启动模式
. The way to prove the effect of throwing exceptions on performance in. Net core
How many rounds of deep learning training? How many iterations?
[JS component] floating text
ImportError: cannot import name &#039; get_ ora_ doc&#039; from partially initialized module
今日睡眠质量记录74分
人神共愤,唐山“群殴女性事件”细节...
OceanBase 雄踞墨天轮2021年度中国数据库魔力象限领导者
[MRCTF2020]Ez_ bypass --BUUCTF
Andersen global expands its business in northern Europe through cooperation agreements in Finland and Denmark
深度学习每周期的步数多少合适?
Kotlin 协程挂起函数 suspend 关键字
硬(磁)盘(二)
Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis
【北亚服务器数据恢复】虚拟机文件丢失导致Hyper-V服务瘫痪的数据恢复案例
【服务器数据恢复】存储服务器之间迁移数据时数据丢失恢复成功案例
Andersen Global通过在芬兰和丹麦的合作协议拓展北欧地区业务版图
The seventh finals of the Blue Bridge Cup
Ad14 component pin name disappeared