Cod sursa(job #2791922)

Utilizator DragosC1Dragos DragosC1 Data 31 octombrie 2021 13:54:03
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <algorithm>
using namespace std;

long long a[277000];
const int n = 276997;
string s;
int cnt;

long long get_nr(string x) {
    int i;
    long long nr = 0;
    for (i = 0; i < s.size(); i++)
        nr = nr * 10 + s[i] - '0';
    return nr;
}

void read() {
    int i, Q, st, dr, mij;
    long long x;
    ifstream f("dtcsu.in");
    for (i = 1; i <= n; i++) {
        f >> s;
        a[i] = get_nr(s);
    }
    sort(a + 1, a + n + 1);
    f >> Q;
    for (i = 1; i <= Q; i++) {
        f >> s;
        x = get_nr(s);
        st = 1, dr = n;
        while (st <= dr) {
            mij = (st + dr) / 2;
            if (a[mij] == x) {
                cnt++;
                break;
            }
            else if (a[mij] < x)
                st = mij - 1;
            else dr = mij - 1;
        }
    }
    f.close();
}

void output() {
    ofstream g("dtcsu.out");
    g << cnt;
    g.close();
}

int main() {
    read();
    output();
    return 0;
}