如何求出两个数组一共有多少个值不相等的元素

如何求出两个数组一共有多少个值不相等的元素

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
bool compare(int a,int b)
{
    return a<b; 
}
int main()
{
    int count=0;
    int i,j,z=0;
    int a[10]={1,5,5,5,6,0,3,2,7,4};
    int b[5]={2,1,5,3,5};
    int c[15];
    for(i=0;i<10;i++)//将两个数组 合并成一个数组 
    {
        c[z]=a[i];
        z++;
    }
    for(j=0;j<5;j++)
    {
        c[z]=b[j];
        z++;
    }//
    sort(c,c+15);//排序 
    for(i=0;i<15;i++)
       cout<<c[i]<<" ";
    cout<<endl;
    for(i=0;i<15;i++)//查找 
    {
        if(c[i]!=c[i+1])
           count++;
    }
    cout<<"count="<<count<<endl;
    return 0;
} 

猜你喜欢

转载自blog.csdn.net/weixin_41112564/article/details/81505607
今日推荐