【C++】CCF例题(2013-12)

技巧:

1、数组越界问题
const int maxn=2e5+5;   // 2*10^{5}
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;
}

2013-12-2、ISBN 号码:0-670-82162-4

0×1+6×2+……+2×9=1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值