hdu 4565 So Easy!
2015-07-29 20:08
429 查看
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.
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, \ldots, a_n$ - represents the content of the first
file. The third line contains n integers $b_1, b_2, b_3, \ldots, b_n$ - represents the content of the second file.
Process to the end of file.
$1 \leq n \leq 100$
$1 \leq a_i , b_i \leq 1000000000$
Output
For each case, output "YES" (without quote) if these two files are same, otherwise output "NO" (without quote).
Sample Input
Sample Output
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.
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, \ldots, a_n$ - represents the content of the first
file. The third line contains n integers $b_1, b_2, b_3, \ldots, b_n$ - represents the content of the second file.
Process to the end of file.
$1 \leq n \leq 100$
$1 \leq a_i , b_i \leq 1000000000$
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 统计是否上下两次输入中是否上次输入的下次都能找到,反过来也是。 //AC #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<ctype.h> #include<iostream> #include<string> #include<algorithm> #include<set> #include<vector> #include<queue> #include<map> #include<numeric> #include<stack> #include<list> const int INF=1<<30; const int inf=-(1<<30); using namespace std; int a[111],b[111],c[111]; bool s(int n) { for(int i=0; i<n; i++) //判断是否a数组中的元素在b数组中都能找到 for(int j=0; j<n; j++) { if(a[i]==b[j]) { break; } else if(a[i]!=b[j]&&j==n-1) //此时说明未找到 return false; } for(int i=0; i<n; i++) for(int j=0; j<n; j++) { if(b[i]==a[j]) { break; } else if(b[i]!=a[j]&&j==n-1) return false; } return true; } int main() { int n; while(cin>>n) { for(int i=0; i<n; i++) { c[i]=0; scanf("%d",&a[i]); } sort(a,a+n); for(int i=0; i<n; i++) { scanf("%d",&b[i]); } sort(b,b+n); bool it=s(n); if(it) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- zedboard原理图解析及相关datasheet
- java安全性语言
- debug : StartService failed, getlasterror = 0x7f(127) 转
- Qt:电子时钟
- 每天一个小知识点17(Angularjs总结五)
- hdoj5323
- 生成树相关问题
- SpringMVC-DispatcheServlet
- spark1.2 使用breeze 的 netlib.BLAS 异常
- [python]学习笔记3-字符串内建函数2
- mysql常见优化
- [HDU 1521] 排列组合 指数型母函数
- LeetCode || Validate Binary Search Tree
- Detecting diabetic retinopathy in eye images
- POJ 1679 The Unique MST
- c++ 11 新特性
- 18.4Sum (Map)
- #1128 : 二分·二分查找
- hls 类型
- HDOJ 1863 畅通工程(最小生成树--kruskal)