ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

WA on test 10. Does anyone have any tips on how to solve it (and/or) where's my bug?
Posted by Learning_C 21 Sep 2004 14:32
#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;
}