7.27
- import java.util.Scanner;
- public class equalArray2 {
- public static void main(String[] args) {
- int iNum1; // input size of array
- int i;
- Scanner input = new Scanner(System.in);
- iNum1 = input.nextInt();
- int []iArray1 = new int[iNum1+1];
- for ( i=0 ; i<iNum1 ; i++ )
- iArray1[i] = input.nextInt();
- int iNum2;
- iNum2 = input.nextInt();
- int []iArray2 = new int[iNum2+1];
- for ( i=0 ; i<iNum1 ; i++ )
- iArray2[i] = input.nextInt();
- if ( equals(iArray1,iArray2) == true )
- System.out.println("identical array!");
- else
- System.out.println("different array! ");
- }
- public static boolean equals( int[] list, int[] list2 )
- {
- int[] iBucket = new int [20];
- int []iBucket2 = new int[20];
- boolean bTemp = false;
- int i;
- for ( i=0 ;i<20 ; i++ )
- iBucket[i] = iBucket2[i] = 0;
- i = 0;
- while (list[i]!=0)
- {
- iBucket[list[i]]++;
- i++;
- }
- int j;
- j = 0;
- while (list2[j]!= 0)
- {
- iBucket2[list2[j]]++;
- j++;
- }
- for ( i=0 ; i<20 ; i++ )
- {
- if (iBucket[i] == iBucket2[i])
- bTemp = true;
- else
- {
- bTemp = false;
- break;
- }
- }
- return bTemp;
- }
- }
留言
張貼留言