zoukankan      html  css  js  c++  java
  • So easy

    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 #include <stdio.h> 
      2 
      3 int main(){
      4     int n;
      5     int number;
      6     int i;
      7     int j;
      8     int array1[101];
      9     int array2[101];
     10     int length1;
     11     int length2;
     12     int temp;
     13 
     14     while(scanf("%d",&n)!=EOF){
     15         length1=0;
     16         for(i=0;i<n;i++){
     17             scanf("%d",&number);
     18 
     19             if(i==0){
     20                 array1[0]=number;
     21                 length1++;
     22                 continue;
     23             }
     24 
     25             for(j=0;j<length1;j++){
     26                 if(number==array1[j])
     27                     break;
     28             }
     29 
     30             if(j==length1){
     31                 array1[length1]=number;
     32                 length1++;
     33             }
     34         }
     35 
     36         for(i=0;i<length1-1;i++){
     37             for(j=i+1;j<length1;j++){
     38                 if(array1[i]>array1[j]){
     39                     temp=array1[i];
     40                     array1[i]=array1[j];
     41                     array1[j]=temp;
     42                 }
     43             }
     44         }
     45 
     46         /*for(i=0;i<length1;i++)
     47             printf("%d ",array1[i]);
     48         printf("
    ");*/
     49 
     50         length2=0;
     51         for(i=0;i<n;i++){
     52             scanf("%d",&number);
     53 
     54             if(i==0){
     55                 array2[0]=number;
     56                 length2++;
     57                 continue;
     58             }
     59 
     60             for(j=0;j<length2;j++){
     61                 if(number==array2[j])
     62                     break;
     63             }
     64 
     65             if(j==length2){
     66                 array2[length2]=number;
     67                 length2++;
     68             }
     69         }
     70 
     71         for(i=0;i<length2-1;i++){
     72             for(j=i+1;j<length2;j++){
     73                 if(array2[i]>array2[j]){
     74                     temp=array2[i];
     75                     array2[i]=array2[j];
     76                     array2[j]=temp;
     77                 }
     78             }
     79         }
     80 
     81         /*for(i=0;i<length2;i++)
     82             printf("%d ",array2[i]);
     83         printf("
    ");*/
     84 
     85         if(length1!=length2){
     86             printf("NO
    ");
     87             continue;
     88         }
     89 
     90         for(i=0;i<length1;i++){
     91             if(array1[i]!=array2[i]){
     92                 printf("NO
    ");
     93                 break;
     94             }
     95         }
     96 
     97         if(i==length1)
     98             printf("YES
    ");
     99 
    100     }
    101         
    102     return 0;
    103 }
  • 相关阅读:
    (void) (&_x == &_y)的作用
    GNU C 与 ANSI C(下)
    GNU C 与 ANSI C(上)
    “多个单核CPU”与“单个多核CPU”哪种方式性能较强?
    ARM 处理器寻址方式之间接寻址的几种表达
    Video for Linux Two API Specification
    UVC 驱动调用过程与驱动框架的简单分析
    线程安全
    合法的立即数的判断
    Redis的Java客户端Jedis
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4079949.html
Copyright © 2011-2022 走看看