CCF真题 201312-1 出现次数最多的数
生活随笔
收集整理的这篇文章主要介绍了
CCF真题 201312-1 出现次数最多的数
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
目录
- 1 题目
- 1.1 问题描述
- 1.2 输入格式
- 1.3 输出格式
- 1.4 样例输入
- 1.5 样例输出
- 2 代码
1 题目
1.1 问题描述
给定n个正整数,找出它们中出现次数最多的数。如果这样的数有多个,请输出其中最小的一个。
1.2 输入格式
输入的第一行只有一个正整数n(1 ≤ n ≤ 1000),表示数字的个数。
输入的第二行有n个整数s1, s2, …, sn (1 ≤ si ≤ 10000, 1 ≤ i ≤ n)。相邻的数用空格分隔。
1.3 输出格式
输出这n个次数中出现次数最多的数。如果这样的数有多个,输出其中最小的一个。
1.4 样例输入
6
10 1 10 20 30 20
1.5 样例输出
10
2 代码
#include<iostream> #include<algorithm> using namespace std; struct nummm {int count;int num; }; bool cmp(nummm n1,nummm n2) {if(n1.count==n2.count){return n1.num<n2.num;}else{return n1.count>n2.count;} } int main() {int n=0;cin>>n;nummm *nu=new nummm [n];for(int i=0;i<n;i++){cin>>nu[i].num;nu[i].count=0;}for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){if(nu[i].num==nu[j].num){nu[i].count++;}}} sort(nu,nu+n,cmp);cout<<nu[0].num<<endl;return 0; }总结
以上是生活随笔为你收集整理的CCF真题 201312-1 出现次数最多的数的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: PowerDesigner基本使用
- 下一篇: CCF真题 201312-2 ISBN