# 华为上机题目之数组比较

例如：array1[]={1,3,5},array2[]={7,12,1,3,5},返回值是0；

array1[]={1,3,5},array2[]={7,12,1,3,5,88},返回值是3；

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int array_compare(int len1,int array1[],int len2,int array2[])
{
int count=0;

if(len1 == len2)
{
for(;len1>0&&len2>0;len1--,len2--)
{
if(array1[len1-1] != array2[len2-1])
{
count++;
}
}
}
if(len1>len2)
{
int i;
int j;
for(i=0;i<len2;i++)
{
for(j=0;j<len1;j++)
{
if(array1[i] == array2[j])
{
count++;
}
}
}
count = len1-count;
}
if(len1<len2)
{
int i;
int j;
for(i=0;i<len1;i++)
{
for(j=0;j<len2;j++)
{
if(array1[i] == array2[j])
{
count++;

}
}
}
count = len2-count;
}
return count;

}

int main()
{
int result;
int array1[]={1,3,5,8,9};
int len1=5;
int array2[]={1,3,5,8,8};
int len2=5;

result = array_compare(len1,array1,len2,array2);

printf("the final result is %d\n",result);

}

bossjuemfc

• 擅长领域：
• Linux
• Python
• go
• docker
• kubernetes

03-31 822

04-06 1.2万

08-30 565

09-22 567

02-27 797

07-05 1651

07-06 959

09-21 1256

09-10 1021

04-09 1493