C + + String programming Training 4

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.