【UVA】10763 Foreign Exchange(map)

题目

题目
 


分析

没什么好说的,字符串拼接一下再放进map。其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法。
呃400ms,有点慢。
 


代码

#include <bits/stdc++.h>
using namespace std;
int read(string a)
{
	int ans=0,i=0;
	while(i<a.length()){ans=(ans<<3)+(ans<<1)+a[i]-'0';i++;}
	return ans;
}
int main()
{
	int n;
	while(cin>>n && n!=0)
	{
		map<string,int> ex;
		int maxnum=-1,minnum=1<<13;
		for(int i=0;i<n;i++)
		{
			string x,y; int a,b;
			cin>>x>>y;
			a=read(x);b=read(y);
			minnum=min(minnum,a);minnum=min(minnum,b);
			maxnum=max(maxnum,a);maxnum=max(maxnum,b);
			ex[x+y]++; ex[y+x]--;
		}
		bool ok=true;
		map<string,int>::iterator it;
		it=ex.begin();
		while(it!=ex.end()){
			if(it->second!=0) ok=false;
			it++;
		}
		if(ok) puts("YES");
		else puts("NO");
	}
	return 0;
}
原文地址:https://www.cnblogs.com/noblex/p/7868207.html