uva 10763 Foreign Exchange

map应用        简单题目

#include 
#include 
using namespace std;

struct node
{
	int start;
	int end;
};

bool operator < (const struct node &a, const struct node &b)
{
	unsigned long long aa, bb;

	aa = a.start;
	aa = aa << 32;
	aa += a.end;

	bb = b.start;
	bb = bb << 32;
	bb += b.end;

	return aa < bb;
}

map< struct node, int > m;

int main(void)
{
	int n, i, t;
	struct node no;
	bool f;
	map::iterator it;

	//freopen("input.dat", "r", stdin);

	while(scanf("%d",&n), n)
	{
		m.clear();
		for(i=1; i<=n; i++)
		{
			scanf("%d %d", &(no.start), &(no.end));

			if(no.start < no.end)
			{
				if(m.find(no) == m.end())
					m[no] = 1;
				else
					m[no] = m[no]+1;
			}
			else
			{
				t = no.start;
				no.start = no.end;
				no.end = t;

				if(m.find(no) == m.end())
					m[no] = -1;
				else
					m[no] = m[no]-1;
			}
		}
		f = true;
		for(it=m.begin(); it!=m.end(); it++)
		{
			if(it->second != 0)
			{
				f = false;
				break;
			}
		}

		if(f)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}


你可能感兴趣的:(acm)