zoukankan      html  css  js  c++  java
  • HDU5058

    So easy

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 991    Accepted Submission(s): 547


    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.
     

    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 a1,a2,a3,,an - represents the content of the first file. The third line contains n integers b1,b2,b3,,bn - represents the content of the second file.
    Process to the end of file.
    1n100
    1ai,bi1000000000
     

    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
     
    水题……
     1 //2016.8.12
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<set>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n;
    11     while(cin>>n)
    12     {
    13         set<int> seta;
    14         set<int> setb;
    15         int a, b;
    16         bool fg = true;
    17         for(int i = 0; i < n; i++)
    18         {
    19             scanf("%d", &a);
    20             seta.insert(a);
    21         }
    22         for(int i = 0; i < n; i++)
    23         {
    24             scanf("%d", &b);
    25             setb.insert(b);
    26         }
    27         if(seta.size()!=setb.size())
    28           fg = false;
    29         else{
    30             set<int>::iterator it;
    31             for(it = seta.begin(); it != seta.end(); it++)
    32             {
    33                 if(setb.count(*it)==0)
    34                   fg = false;
    35             }
    36         }
    37         if(fg)cout<<"YES"<<endl;
    38         else cout<<"NO"<<endl;
    39     }
    40 
    41     return 0;
    42 }
  • 相关阅读:
    提交暂存更改时报 is outside repository 解决办法
    vue 路由跳转传参
    Unexpected token u in JSON at position 0 解决
    解决element table错位的问题
    使用docker制作Mysql镜像
    Linux系统性能排查
    分盘挂载
    Shell中的变量
    Shell流程控制
    Shell条件判断
  • 原文地址:https://www.cnblogs.com/Penn000/p/5766762.html
Copyright © 2011-2022 走看看