将输入的2个数转换为一个string,两个数之间加一个分隔符,用map标记相同string,统计次数
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<sstream>
#include<cmath>
using namespace std;
/**********************************************************/
const int MAX_NUM = 500000+100;
int KVcount[MAX_NUM];
map<string,int> KV_ID;
/**********************************************************/
int min_2 (int x,int y) {return x<y?x:y;}
int max_2 (int x,int y) {return x>y?x:y;}
/**********************************************************/
int main()
{
//freopen ("in.txt","r",stdin);
int n;
while (cin>>n && n)
{
string a,b,c,d;
memset (KVcount,0,sizeof (KVcount));
KV_ID.clear ();
int kvlen=0;
for (int i=0;i<n;i++)
{
cin>>a>>b;
c=a+"#"+b,d=b+"#"+a;
if (KV_ID.count (c)==0){
if (KV_ID.count (d)==0){
KV_ID[c]=kvlen;//如果a-b不存在,分配id
kvlen+=2;
}
else KV_ID[c]=KV_ID[d]+1;
}
++KVcount[KV_ID[c]];
}
int sign=1;
for (int i=0;i+1<kvlen;i+=2)
if (KVcount[i]!=KVcount[i+1]){
sign=0;
break;
}
if (sign) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}