WA on test 10. Does anyone have any tips on how to solve it (and/or) where's my bug?
#include <stdio.h>
#define MaxP 100000
#define MaxT 15000
long Pup,Teach,LiP[MaxP],LiT[MaxT],matching;
long cmp (const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
void find (long x)
{
long wskT=1,wskP=1;
while((wskT<=Teach)&&(wskP<=x))
if (LiP[wskP]==LiT[wskT])
{
matching++;
wskP++;
}
else if(LiP[wskP]<LiT[wskT])
wskP++;
else if (LiP[wskP]>LiT[wskT])
wskT++;
}
int main(void)
{
long i;
scanf("%d",&Teach);
for (i=1;(i<=Teach)&&(scanf("%d",LiT+i));i++);
scanf("%d",&Pup);
if (Pup>=MaxP)
{
long part=MaxP,rest=Pup-MaxP;
do
{
for (i=1;(i<=part)&&(scanf("%d",LiP+i));i++);
qsort(LiP,part+1,sizeof(unsigned int), cmp);
find(part);
if (rest>=MaxP) {part=MaxP;rest-=MaxP;}
else {part=rest;rest=0;}
}
while (part>0);
}
else
{
for (i=1;(i<=Pup)&&(scanf("%d",LiP+i));i++);
qsort(LiP,Pup+1,sizeof(unsigned int), cmp);
find(Pup);
}
printf("%d",matching);
return 0;
}