So easy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 160 Accepted Submission(s): 104
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.
Process to the end of file.
$1 \leq n \leq 100$
$1 \leq a_i , b_i \leq 1000000000$
題解及代碼:
簡單題,用一個map模擬,前n個數的map值記爲1,之後n個數的map值+1,最後判斷是否所有map值都大於2.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
map<int,int>m;
map<int,int>::iterator it;
int main()
{
int n,x;
while(scanf("%d",&n)!=EOF)
{
m.clear();
for(int i=0;i<n;i++)
{
scanf("%d",&x);
m[x]=1;
}
for(int i=0;i<n;i++)
{
scanf("%d",&x);
m[x]++;
}
bool flag = true;
for(it=m.begin();it!=m.end();it++)
if(it->second<2)
{
flag= false;
break;
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}