Cod sursa(job #2315029)

Utilizator Mihai145Oprea Mihai Adrian Mihai145 Data 9 ianuarie 2019 12:54:54
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <string>
#include <map>

#define P 983095237

using namespace std;

ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");

int Q, sol;
string s;

map <int, bool> ap;

inline int Hash(string s)
{
    int ret = 0;

    for(int i = 0; i < s.size(); i++)
        ret = (ret + (s[i] - '0') * 10) % P;

    return ret;
}

int main()
{
    for(int i = 1; i <= 276997; i++)
        {
            fin >> s;

            int hashh = Hash(s);

            ap[hashh] = 1;
        }

    fin >> Q;

    for(int i = 1; i <= Q; i++)
    {
        fin >> s;

        if(s[0] == '-')
            continue;

        if(ap[Hash(s)] == 1)
            sol++;
    }

    fout << sol;
}