Cod sursa(job #1784038)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 19 octombrie 2016 18:44:39
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda hash_excelenta Marime 0.66 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("dtcsu.in");
ofstream g("dtcsu.out");
long long v1[280002];
int n,s;
long long nr;
bool binary(long long nr)
{
    int a=1;
    int b=276997;
    while(a!=b)
    {
        int m=(a+b)/2;
        if(v1[m]==nr)
            return true;
        else
            if(v1[m]<nr)
                a=m+1;
            else
                b=m-1;
    }
    return false;
}
int main()
{
    for(int i=1;i<=276997;++i)
    {
        f>>v1[i];
    }
    sort(v1+1,v1+276998);
    f>>n;
    for(int i=1;i<=n;++i)
    {
        f>>nr;
        s+=binary(nr);
    }
    g<<s<<'\n';
    g.close();
}