CCSP201312-1出现次数最多的数

时间:2019-11-18
本文章向大家介绍CCSP201312-1出现次数最多的数,主要包括CCSP201312-1出现次数最多的数使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

代码

#include <iostream>
using namespace std;

int main() {
    int n,max=0,max_num=0;
    int *array = new int[1000];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>array[i];
    int count[10001] = {0};
    for(int i=0;i<n;i++)
    {
        count[array[i]]++;
    }
    for(int i=0;i<10001;i++)
    {
        if(count[i]>max)
        {
            max=count[i];
            max_num=i;
        }
    }
    cout<<max_num<<endl;
    return 0;
}

知识点总结:

1. 动态一维数组:int * array = new int[size];

2. map用法:

//头文件 
#include<map>
//定义
map<int, string> mapStudent;
//插入元素
// 第一种 用insert函数插入pair
mapStudent.insert(pair<int, string>(000, "student_zero"));
 
// 第二种 用insert函数插入value_type数据
mapStudent.insert(map<int, string>::value_type(001, "student_one"));
 
// 第三种 用"array"方式插入
mapStudent[123] = "student_first";
mapStudent[456] = "student_second";

关于map:https://blog.csdn.net/sevenjoin/article/details/81943864

原文地址:https://www.cnblogs.com/QRain/p/11880257.html