C++STL

本文提供了一个使用 C++ 实现的数据结构操作示例,包括 sort、vector、priority_queue、set 和 map 的基本用法,并定义了一个自定义结构体 test 用于存储整数对并实现比较操作。
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<deque>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define rep(x) for (int i=0;i<x;i++) 
#define repc(c) for (typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back

struct test
{
	int x,y;
	bool operator <(const test& other) const
	{
		return x<other.x || (x==other.x && y<other.y);
	}
	bool operator ==(const test& other) const
	{
		return x==other.x && y==other.y; 
	}
};

test a[1000];
vector<test> v;
set<test> s;
priority_queue<test> q;
map<test,int> m;
int n,idx;

void input()
{
	scanf("%d\n",&n);
	rep(n) scanf("%d %d\n",&a[i].x,&a[i].y);
}

void output()
{
	rep(n) printf("%d %d\n",a[i].x,a[i].y);
	printf("-------\n");
}



int main()
{
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	
	input();
	
	/*------sort------*/
	
	/*
	sort(a,a+n);
	output();
	*/
	
	/*------vector------*/
	
	/*
	rep(n) v.pb(a[i]);
	repc(v) printf("%d %d\n",i->x,i->y);
	*/
	
	/*------priority_queue------*/
	
	/* 
	rep(n) q.push(a[i]);
	while (!q.empty())
	{
		printf("%d %d\n",q.top().x,q.top().y);
		q.pop();
	}
	*/

	/*------set------*/
	
	/*
	rep(n) s.insert(a[i]);
	repc(s) printf("%d %d\n",i->x,i->y);
	*/
	
	/*------map------*/
	
	/*
	idx=0; 
	rep(n) if (m[a[i]]==0) m[a[i]]=++idx;
	rep(n) printf("%d\n",m[a[i]]);
	*/
	
	
	return 0;
}

  

转载于:https://www.cnblogs.com/exponent/archive/2012/11/09/2762031.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值