暑假集训第三周周三赛 STL A - So easy 判断集合
来源:互联网 发布:对你一直有空 知乎 编辑:程序博客网 时间:2024/05/29 13:06
A - So easy
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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
可能昨天就是心情不好吧,提都不想做,就这一道都是好不容易才做的。
这题就是找他们的集合是不是相同,所以要用set
它的作用主要就是去重,排序,如果经过处理后他们的集合一样,就输出YES
set只有一个自变量,所以没有first或second,只能用*p1!=*p2
12345678910111213141516171819202122232425262728293031323334353637383940414243
#include<stdio.h>#include<algorithm>#include<set>using namespace std;int main(){ int n,a,i,f; set<int>s1,s2; while(scanf("%d",&n)!=EOF) { s1.clear(); s2.clear(); for(i=0; i<n; i++) { scanf("%d",&a); s1.insert(a); } for(i=0; i<n; i++) { scanf("%d",&a); s2.insert(a); } if(s1.size()!=s2.size()) printf("NO\n"); else { f=0; set<int>::iterator p1,p2; for(p1=s1.begin(),p2=s2.begin(); p1!=s1.end()&&p2!=s2.end(); p1++,p2++) if(*p1!=*p2) { f=1; break; } if(f==0) printf("YES\n"); else printf("NO\n"); } } return 0;}
0 0
- 暑假集训第三周周三赛 STL A - So easy 判断集合
- 暑假集训第三周周三赛 STL D - 产生冠军
- 暑假集训第三周周三赛 STL E - Gunner 射鸟
- 暑假集训第三周周三赛 STL F - 水果
- 暑假集训第三周周三赛 STL G - Intelligent IME
- AYIT2017暑假集训第三周周三赛 A
- 暑假集训第三周周三赛 STL C - Strange Class 字符相同 SC数
- AYIT2017暑假集训第二周周三赛 A
- 暑假集训第三周周六赛 STL D - 胜利大逃亡
- 暑假集训第四周周三赛F - Knight Moves 骑士的移动 STL
- 暑假集训大二第一周周三赛 A仙人掌的残影
- AYIT2017暑假集训第二周周三赛 B
- AYIT2017暑假集训第二周周三赛 C
- AYIT2017暑假集训第二周周三赛 G
- AYIT2017暑假集训第二周周三赛 D
- AYIT2017暑假集训第二周周三赛 E
- 暑假集训第三周周六赛 搜索 B - Red and Black红黑瓷片
- 暑假集训第三周周六赛 搜索 E - N皇后问题
- mapreduce--使用自定义类做value
- MVC程序设计模式
- 可自动切换选项卡
- Html JS实现表单验证
- C - Segment set
- 暑假集训第三周周三赛 STL A - So easy 判断集合
- POJ 3974 Palindrome【Manacher】
- 2015 Multi-University Training Contest 4
- Java 警告------Type safety: The method add(Object) belongs to the raw type Vector
- Markdown
- 数组旋转
- Caused by: java.lang.NumberFormatException: For input string: ""
- AngularStrap -- Popovers
- DOM解析XML