【ACM打卡】ZOJ 3019

3019 输入俩数组,用sort()排序,找出相同的元素个数、并输出。

   EOF:end of file ,结束输入,否则会超时。(不太懂- -)


3019

#include<iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define M 10001
#define N 10001
int a[M],b[N];
int main(){
   
    int x,y,i,j,n;
   while(scanf("%d%d",&x,&y)!=EOF)
   {
       for(i=0;i<x;i++){
        cin>>a[i];
    }
    for(j=0;j<y;j++){
        cin>>b[j];
    }
    sort(a,a+x);
    sort(b,b+y);

    n=0,i=j=0;
    while(i!=x&&j!=y){

        if(a[i]==b[j]){
            i++;
            j++;
            n++;
        }
        else if(a[i]<b[j]) i++;
        else j++;
    }
    cout<<n<<endl;
   }
    return 0;
}


原文地址:https://www.cnblogs.com/iriswang/p/11084681.html