So easy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 550 Accepted Submission(s): 298
Problem Description
Small W gets two files. There are n integers in each file. Small W wants to know whether these two files are same. So he invites you to write a program to check whether these two files are same. Small W thinks that two files are same when they have the same integer set.
For example file A contains (5,3,7,7),and file B contains (7,5,3,3). They have the same integer set (3,5,7), so they are same.
Another sample file C contains(2,5,2,5), and file D contains (2,5,2,3).
The integer set of C is (2,5),but the integer set of D is (2,3,5),so they are not same.
Now you are expected to write a program to compare two files with size of n.
For example file A contains (5,3,7,7),and file B contains (7,5,3,3). They have the same integer set (3,5,7), so they are same.
Another sample file C contains(2,5,2,5), and file D contains (2,5,2,3).
The integer set of C is (2,5),but the integer set of D is (2,3,5),so they are not same.
Now you are expected to write a program to compare two files with size of n.
Input
Multi test cases (about 100). Each case contain three lines. The first line contains one integer n represents the size of file. The second line contains n integers
a
1
,a
2
,a
3
,…,a
n![]()
- represents the content of the first file. The third line contains n integers
b
1
,b
2
,b
3
,…,b
n![]()
- represents the content of the second file.
Process to the end of file.
1≤n≤100
1≤a
i
,b
i
≤1000000000
Process to the end of file.
1≤n≤100
1≤a
Output
For each case, output "YES" (without quote) if these two files are same, otherwise output "NO" (without quote).
Sample Input
3 1 1 2 1 2 2 4 5 3 7 7 7 5 3 3 4 2 5 2 3 2 5 2 5 3 1 2 3 1 2 4
Sample Output
YES YES NO NO
STL 之 set 的应用
#include<stdio.h>
#include<set>
using namespace std;
set<int>a;
set<int>b;
int main()
{
int n,m;
int i;
while(scanf("%d",&n)!=EOF)
{
a.clear();
b.clear();
for(i=0;i<n;i++)
{
scanf("%d",&m);
a.insert(m);
}
for(i=0;i<n;i++)
{
scanf("%d",&m);
b.insert(m);
}
if(a==b)
{
puts("YES");
}
else
{
puts("NO");
}
}
return 0;
}