其他分享
首页 > 其他分享> > HDU5058(set应用)

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;
}

标签:set,应用,HDU5058,int,st1,st2,include,it2,it1
来源: https://blog.csdn.net/Keep_Trying_Go/article/details/113978068