HDU5058(set应用)

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
int n;
int main(){
	while(cin>>n){
		set<int>st1;
		set<int>st2;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			if(st1.find(x)==st1.end()){
				st1.insert(x);
			}
		}
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			if(st2.find(x)==st2.end()){
				st2.insert(x);
			}
		}
		if(st1.size()!=st2.size()){
			cout<<"NO"<<endl;
		}else{
			int flag=0;
			set<int>::iterator it1;
			set<int>::iterator it2;
			for(it1=st1.begin(),it2=st2.begin();it1!=st1.end(),it2!=st2.end();++it1,++it2){
				if(*it1!=*it2){
					flag=1;
				}
			}
			if(flag==0){
				cout<<"YES"<<endl;
			}else{
				cout<<"NO"<<endl;
			}
		}
	}
	return 0;
}
上一篇:C#基础(二):enum与struct


下一篇:1065 单身狗 (25 分)