HDU 5058 So easy(STL set运用)
来源:互联网 发布:无线有限制的网络连接 编辑:程序博客网 时间:2024/05/01 17:13
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5058
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, \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$
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
31 1 21 2 245 3 7 77 5 3 342 5 2 32 5 2 531 2 31 2 4
Sample Output
YESYESNONO
Source
BestCoder Round #12
代码如下:
#include <cstdio>#include <algorithm>#include <set>using namespace std;int main(){ set<int>s1,s2; int n; while(~scanf("%d",&n)) { s1.clear(); s2.clear(); int tt; for(int i = 0; i < n; i++) { scanf("%d",&tt); s1.insert(tt); } for(int i = 0; i < n; i++) { scanf("%d",&tt); s2.insert(tt); } if(s1.size() != s2.size()) { printf("NO\n"); continue; } int flag = 0; set<int>::iterator it1, it2; for(it1 = s1.begin(),it2 = s2.begin(); it1!=s1.end()&&it2!=s2.end(); it1++,it2++) { if(*it1 != *it2) { flag = 1; break; } } if(flag) { printf("NO\n"); } else printf("YES\n"); } return 0;}
1 0
- HDU 5058 So easy(STL set运用)
- HDU 5058 So easy(STL 集合set的运用)
- HDU-#5058 So easy(set)
- hdu 5058 So easy (set)
- HDU 5058 So easy (set容器大法好)
- hdu 5058 So easy
- HDU 5058 So easy
- hdu 5058 So easy
- hdu 5058 So easy
- HDU 5058 So easy
- hdoj 5058 So easy (简单set)
- HDU5058 So easy 【set】
- 【CUGBACM15级BC第12场 A】【STL】hdu 5058 So easy
- HDU 5058 So easy(水)
- hdu 5058 So easy (排序+离散化)
- HDU 5058/BC 12A So easy
- hdu 5058 So easy(去重)
- [HDU](5058)So easy --去重
- iOS关于iPhone6和iPhone6 Plus的屏幕适配问题
- 中文分词词典构造简述
- 机房收费系统(一)——上下机、总结
- CSS标签
- 插入排序-【Shell排序】
- HDU 5058 So easy(STL set运用)
- windbg win7 本地调试
- nyoj642牛奶
- 使用HorizontalScrollView 实现ListView横向滑动
- BMP085气压传感器驱动
- java中的System.out.print()与System.out.println()的区别
- 设计模式之外观模式-facade
- C++实现8皇后问题
- OO模式-Singleton