Cod sursa(job #2791931)

Utilizator DragosC1Dragos DragosC1 Data 31 octombrie 2021 14:06:39
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <fstream>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

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

long long get_nr() {
    int i, len;
    long long nr = 0;
    len = strlen(s);
    for (i = 0; i < len; i++)
        if (isdigit(s[i]))
            nr = nr * 10 + s[i] - '0';
    return nr;
}

void read() {
    int i, Q, st, dr, mij;
    long long x;
    FILE *f;
    f = fopen("dtcsu.in", "r");
    for (i = 1; i <= n; i++) {
        fgets(s, 20, f);
        a[i] = get_nr();
    }
    sort(a + 1, a + n + 1);
    fgets(s, 20, f);
    Q = get_nr();
    for (i = 1; i <= Q; i++) {
        fgets(s, 20, f);
        x = get_nr();
        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;
        }
    }
}

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

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