技巧:
1、数组越界问题
const int maxn=2e5+5; // 2*
struct node
{
int x,y;
} s[maxn];
2、vector向量去重
sort(temp.begin(), temp.end());
temp.erase(unique(temp.begin(), temp.end()), temp.end()); // unique()返回值:去重以后vector中没有重复元素的下一个位置的迭代器
3、sort(a, a+n, cmp) // (数组起始地址, 结束地址, 默认从小到大排序)
int cmp(node t1,node t2) //自定义排序结构体元 素比较
{
return t1.x>t2.x; // 从大到小
}
int cmp1(node1 t1,node1 t2) // 按sum排序,如果相等,则按x从小到大
{
if(t1.sum==t2.sum)
return t1.x<t2.x;
return t1.sum<t2.sum;
}
2013-12-1、出现次数最多的数
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <map>
using namespace std;
int main()
{
int n;
cin >> n; //n个数
map<int, int> f;
for (int i = 0; i < n; i++)
{
int t;
cin >> t;
f[t]++;
}
int ans, m = 0;
for (map<int, int>::iterator it = f.begin(); it != f.end(); it++)
{
if (it->second > m)
{
m = it->second;
ans = it->first;
}
}
cout << ans << endl;
return 0;
}