Cod sursa(job #2161272)

Utilizator flaviu_2001Craciun Ioan-Flaviu flaviu_2001 Data 11 martie 2018 16:31:17
Problema Trie Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

struct trie{
    trie* f[52];
    trie(){
        memset(f, 0, sizeof(f));
    }
};

trie* rad = new trie;
int sol = 1, n, m;
char c[105];

int main()
{
    ifstream fin ("dictree.in");
    ofstream fout ("dictree.out");
    fin >> n;
    for (int i = 1; i <= n; ++i){
        fin >> c;
        m = strlen(c);
        trie *t = rad;
        for (int j = 0; j < m; ++j){
            int q;
            if(c[j] >= 'a' && c[j] <= 'z')
                q = c[j]-'a'+27;
            else q = c[j]-'A';
            if(t->f[q] == NULL){
                t->f[q] = new trie;
                ++sol;
            }
            t = t->f[q];
        }
    }
    fout << sol << "\n";
    return 0;
}