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

help plz.. why WA1???
Posted by rakeshvarna 29 Nov 2008 23:24
#include<stdio.h>


int main()
{
    int n,m,p,q,r,i;
    int count=0;
    int t[15000];
    int k;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&t[i]);

  scanf("%d",&m);

    for(i=0;i<m;i++)
    {
        scanf("%d",&k);
        p=0;
        r=n-1;
        while(p<=r)
         {
              q=(p+r)/2;
               if(t[q]==k)
               {
                count++;
                p=q+1;

            }
            else if(t[q]<k)
                p=q+1;
            else
                r=q-1;
        }


    }

    printf("%d\n",count);

    return 0;
}