NYOJ intersection set

来源:互联网 发布:淘宝账号无限注册 编辑:程序博客网 时间:2024/06/08 05:39

intersection set

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述
两个集合,你只需要求出两个集合的相同元素,并输出个数。
输入
m n
{a1 , a2 , a3 , a4 ... ai ... am}
{b1 , b2 , b3 , b4 ... bi ... bn}
1 <= n , m <= 50000 , 保证一个集合中不会输入重复数据
0 <= ai , bi <= 100000
多组测试数据
输出
一行一个数据,为两个集合中相同的元素个数
样例输入
8 81 5 6 9 10 12 16 595 6 9 8 15 17 65 98 
样例输出
3
#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;const int max=100005;int a[max];int main(){int i,j,ans,m,n,s;while(scanf("%d%d",&m,&n)!=EOF){memset(a,0,sizeof(a));for(i=0;i<m;++i){scanf("%d",&s);a[s]=1;}ans=0;for(i=0;i<n;++i){scanf("%d",&s);if(a[s]==1)ans++;}printf("%d\n",ans);}return 0;}
0 0