Question:
There are two arrays A and B, which contain the same elements, but the order is different. Only A value of array A and A value of array B can be obtained for comparison. The comparison result is greater than, less than or equal, however, you cannot compare two numbers in the same Array A or B, or obtain A value in an array. Write an algorithm to achieve correct matching.
Solution: traverse two Arrays
Code:
<SPAN style = "FONT-SIZE: 18px"> // arrayMatch. cpp: defines the entry point of the console application. // # Include "stdafx. h "# include <cstdlib> # include <iostream> using namespace std; void matching (int a [], int B [], int k) {int I = 0; while (I <k) {int j = 0; while (j <k) {if (a [I] = B [j]) {cout <"a [" <I <"]" <"match" <"B [" <j <"]" <endl; break;} j ++;} I ++;} cout <endl;} int _ tmain (int argc, _ TCHAR * argv []) {int a [10] = {,}; int B [10] = }; int k = sizeof (a)/sizeof (int); matching (a, B, k); return 0 ;}</SPAN>