#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N];
int n,m; 
int main ()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int j=0;j<m;j++)
    {
        scanf("%d",&b[j]);
    }
    sort(a,a+n);
    sort(b,b+n);
    set<int>s1(a,a+n);
    set<int>s2(b,b+m);
    auto t1=s1.begin();
    auto t2=s2.begin();
    int k=0;
    while(t1!=s1.end()&&t2!=s2.end())
    {
        if(*t1<*t2)
        {
            t1++;
        }
        else if(*t2<*t1)
        {
            t2++;
        }
        else
        {
        
            c[k++]=*t1;    
            t1++;
            t2++;
        }
     } 
     cout<<k<<endl;
     for(int i=0;i<k;i++)
     {
         cout<<c[i]<<" ";
     }
    return 0;
}
//by crtzk7

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐