7.27

  1. import java.util.Scanner;
  2. public class equalArray2 {
  3.     public static void main(String[] args) {
  4.         int iNum1;  // input size of  array
  5.         int i;
  6.         Scanner input = new Scanner(System.in);
  7.         iNum1 = input.nextInt();
  8.         int []iArray1 = new int[iNum1+1];
  9.         for ( i=0 ; i<iNum1 ; i++ )
  10.             iArray1[i] = input.nextInt();
  11.         int iNum2;
  12.         iNum2 = input.nextInt();
  13.         int []iArray2 = new int[iNum2+1];
  14.         for ( i=0 ; i<iNum1 ; i++ )
  15.             iArray2[i] = input.nextInt();
  16.         if ( equals(iArray1,iArray2) == true )
  17.             System.out.println("identical array!");
  18.         else
  19.             System.out.println("different array! ");
  20.         }
  21.         public static boolean equals( int[] list, int[] list2 )
  22.         {  
  23.         int[] iBucket = new int [20];
  24.         int []iBucket2 = new int[20];
  25.         boolean bTemp = false;
  26.         int i;
  27.         for ( i=0 ;i<20 ; i++ )
  28.             iBucket[i] = iBucket2[i] = 0;
  29.         i = 0;
  30.         while (list[i]!=0)
  31.             {
  32.             iBucket[list[i]]++;
  33.             i++;   
  34.             }
  35.         int j;
  36.         j = 0;
  37.         while (list2[j]!= 0)
  38.             {
  39.             iBucket2[list2[j]]++;
  40.             j++;   
  41.             }
  42.         for ( i=0 ; i<20 ; i++ )
  43.         {
  44.         if (iBucket[i] == iBucket2[i])
  45.             bTemp = true;
  46.         else
  47.             {
  48.             bTemp = false;
  49.             break;
  50.             }
  51.         }
  52.         return bTemp;  
  53.     }
  54. }


留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year