This time the topic is a comparison problem, the two arrays from the beginning of the comparison, if the comparison of the two number of different, then the Count plus 1. When one of the arrays has been traversed, the output count value, if the value is 0, indicates that two arrays are the same.
Title: Output two elements with unequal array numbers
Description: Defines a function int array_compare (int len1,int array1[],int len2,int array2[]), where len1 is the length of the array1 array, len2 is the length of the array2 array. The function returns the unequal number of an int value.
int unequal_num (int a[],int len1,int b[],int len2)
{
int num=0;
for (int i=len1-1,j=len2-1;i>=0&&j>=0;i--, j--)
{
if (A[i]!=b[j])
{
num++; Not equal number plus 1
}
}
return num;
}
int main ()
{
int n1,n2;
cin>>n1>>n2;
int *a=new INT[N1];
int *b=new INT[N2];
for (int i=0;i<n1;i++)
{
cin>>a[i]; A array input
}
for (int j=0;j<n2;j++)
{
cin>>b[j]; B Array Input
}
int Res=unequal_num (A,N1,B,N2);
cout<<res;
delete []a;
delete []b;
}
C + + String programming Training 4