CCF之出现次数最多的数

来源:互联网 发布:出国需要下载什么软件 编辑:程序博客网 时间:2024/06/12 20:51
//使用STL容器的map进行统计#include <iostream>#include <map>using namespace std;int main(){    map<int,int> m;    int n,v;    //输入数据,构建Map    cin >> n;    for(int i=0;i<n;i++){        cin >> v;        m[v]++;    }    //找出出现次数最多的数    int ans,count=0;    for(map<int,int>::iterator it=m.begin();it!=m.end();it++){        if(it->second>count){            count=it->second;            ans=it->first;        }    }        //输出结果        cout << ans << endl;        return 0;}

首先导入输入、输出流的头文件<iostream>,

c++输入输出详解

C++的话:

#include <iostream>using namespace std;

STL容器介绍:STLset容器

关于Map(映射):STL7个常用容器比较、深入理解map




原创粉丝点击