当前位置: 首页 > news >正文

2025年重庆大学计算机考研复试机试真题(附 AC 代码 + 解题思路)

2025年重庆大学计算机考研复试机试真题

2025年重庆大学计算机考研复试上机真题

历年重庆大学计算机考研复试上机真题

历年重庆大学计算机考研复试机试真题

更多学校题目开源地址:https://gitcode.com/verticallimit1/noobdream

N 诺 DreamJudge 题库:输入 “学校名称” 即可筛选该校历年机试真题,题目均在考纲范围内,按难度自动排序。还可搭配《计算机考研机试攻略》刷题,书中题目可通过题号直接在题库中查找。

出现次数最多的数

题目描述

Time Limit: 1000 ms
Memory Limit: 256 mb

给定n个正整数,找出它们中出现次数最多的数。如果这样的数有多个,请输出其中最小的一个。

输入输出格式
输入描述:

输入的第一行只有一个正整数n(1 ≤ n ≤ 1000),表示数字的个数。 输入的第二行有n个整数s1, s2, …, sn (1 ≤ si ≤ 10000, 1 ≤ i ≤ n)。相邻的数用空格分隔。

输出描述:

输出这n个次数中出现次数最多的数。如果这样的数有多个,输出其中最小的一个。

输入输出样例
输入样例#:
6 10 1 10 20 30 20
输出样例#:
10

代码一

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n;
  5. cin>>n;
  6. vector<int> v(n);
  7. map<int,int> freq;
  8. for(int i=0;i<n;i++){
  9. cin>>v[i];
  10. freq[v[i]]++;
  11. }
  12. int result=0;int max_count=0;
  13. for(map<int,int>::iterator it=freq.begin();it!=freq.end();++it){
  14. if(it->second>max_count){
  15. result=it->first;
  16. max_count=it->second;
  17. }
  18. else if(it->second==max_count&&it->first<result){
  19. result=it->first;
  20. }
  21. }
  22. cout<<result;
  23. return 0;
  24. }

代码二

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <time.h>
  6. int main() {
  7. int n;
  8. scanf("%d",&n);
  9. int a[1000];
  10. int hash[10001]={0};
  11. int max=0;
  12. int i;
  13. for(i=0;i<n;i++)
  14. {
  15. scanf("%d",&a[i]);
  16. hash[a[i]]++;
  17. if(hash[a[i]]>hash[max]||(hash[a[i]]==hash[max]&&a[i]<max))
  18. {
  19. max=a[i];
  20. }
  21. }
  22. printf("%d\n",max);
  23. return 0;
  24. }

代码三

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. cin>>n;
  6. map<int,int> m;
  7. while(n--){
  8. int temp;
  9. cin>>temp;
  10. if(m.find(temp) == m.end()){
  11. m[temp] = 1;
  12. }else{
  13. m[temp] = m[temp] + 1;
  14. }
  15. }
  16. int minn=10000;
  17. int times = 0;
  18. for(auto x : m){
  19. if(x.second > times){
  20. times = x.second;
  21. minn = x.first;
  22. }else if(x.second == times){
  23. minn = min(minn,x.first);
  24. }else{
  25. }
  26. }
  27. cout<<minn<<endl;
  28. return 0;
  29. }
http://www.rkmt.cn/news/128197.html

相关文章:

  • 医疗模型推理延迟高 后来补TensorRT优化才稳住实时预警
  • Thinkphp和Laravel企业员工薪酬工资管理系统_n4s02htu可视化
  • Linly-Talker姿态微调功能开放,头部动作更自然协调
  • Thinkphp和Laravel基于Vue的农产品助农商城助农商超网站的论坛_rtplg00p
  • 【无人机控制】基于缓解自组织交通堵塞的协作自适应巡航控制算法附Matlab代码
  • Thinkphp和Laravel基于Vue的数学考研试题库管理系统设计与实现_n9s068ni
  • Linux内核参数高并发场景优化:net.ipv4.tcp_fin_timeout
  • 【PostgreSQL】常用SQL
  • 【PostgreSQL】常用SQL
  • 基于python的口腔诊所门诊管理系统的设计与实现_e47798hi
  • 【PostgreSQL】日常总结
  • NTLM Relay
  • 【路径规划】基于混合人工蜂群ABC和粒子群优化PSO算法用于机器人路径规划附matlab代码
  • RedisConnectionMonitor.java
  • 代码重构艺术
  • Java线程池全解:工作原理、参数调优
  • MP4 Downloader Pro(MP4下载器)
  • 51c扩散模型~合集5
  • OncePower文件批量重命名工具
  • 高性能AI聊天工具
  • Tampermonkey
  • idea多模块项目运行设置
  • 解析 `React Native New Architecture`:如何通过 Codegen 保证 JS 层与 C++ 层的类型安全性?
  • 【三相变压器电流行为的特性】模拟心式变压器在不同连接方式下的运行特性附Simulink仿真
  • 深入 React 源码中的 ‘Flags’ 位掩码:引擎如何通过一个整数记录 Fiber 节点的所有待执行操作?
  • Level 7 → Level 8
  • 熵特征提取算法对比详解:从原理到实战
  • 【风光场景生成】基于改进ISODATA的负荷曲线聚类算法(Matlab代码实现)
  • 跳出局部优化思维:构建高性能大规模RAG系统的系统级方法论!
  • 基于SSM的奶茶店管理系统【源码+文档+调试】