描述
Given two integer sets A and B sorted descendingly, you are asked to output the element count of A∩B.
输入
Standard input will contain multiple test cases.
The first line of the input is a single integrate T (1 <= T <= 50) which is the number of test cases. then T consecutive test cases followed.
In each test case, there has four lines.
The first line contains the element count N(1<=N<=100000) for the first set.
The second line contains N integers in the first set.
The third lin
#include<stdio.h>
int main()
{
int t,n,a[100000],b[100000],m,i,j,c;
scanf("%d",&t);
while(t--)
{
c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
i=0;j=0;
while(i<n&&j<m)
{
if(a[i]>b[j])
{
i++;
}
else if(a[i]<b[j])
{
j++;
}
else if(a[i]==b[j])
{
i++;
j++;
c++;
}
}
printf("%d\n",c);
}
return 0;
}
用多组循环可以做,但容易超时