【习题5-4 UVA-10763】Foreign Exchange

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

如果x>y 则num[(x,y)]--; 否则num[(x,y)]++; 看看每一个二元组的num值是不是都为0就好。

【代码】

#include <bits/stdc++.h>
using namespace std;

int n;
map <pair<int, int>, int> mmap;

int main()
{
	//freopen("F:\\rush.txt", "r", stdin);
	while (~scanf("%d", &n) && n)
	{
		mmap.clear();
		for (int i = 0; i < n; i++)
		{
			int x, y;
			scanf("%d%d", &x, &y);
			if (x > y)
			{
				swap(x, y);
				mmap[make_pair(x, y)]--;
			}
			else
				mmap[make_pair(x, y)]++;
		}
		bool ok = true;
		for (auto temp : mmap)
		{
			if (temp.second!=0)
			{
				ok = false;
				break;
			}
		}
		if (ok)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}
posted @ 2017-10-14 20:02  AWCXV  阅读(104)  评论(0编辑  收藏  举报