Cod sursa(job #979601)

Utilizator misinozzz zzz misino Data 2 august 2013 01:29:55
Problema Restante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#include<fstream>
#include<vector>
#include<cstring>
#define MOD 666013
#define B 257
using namespace std;
ifstream f("restante.in");
ofstream g("restante.out");
int n,i,j,m,has,sol;
char s[20];
vector<int>v;
struct nod{
    int has,nr;
    vector<int>v1;
    nod *fiu;
};
nod *h[MOD];
inline void adauga(int val)
{
    nod *x=new nod;
    x->has=val;
    x->v1=v;
    x->nr=1;
    x->fiu=h[val];
    h[val]=x;
}
inline bool exista(int val)
{
    nod *x=h[val];
    while(x&&x->v1!=v)
    {
        x=x->fiu;
    }
    if(x)
    return 1;
    return 0;
}
inline void update(int val)
{
    nod *x=h[val];
    while(x->v1!=v)
    {
        x=x->fiu;
    }
    ++x->nr;
}
inline int decatunu(int val)
{
    nod *x=h[val];
    int sol=0;
    while(x)
    {
        if(x->nr==1)
        ++sol;
        x=x->fiu;
    }
    return sol;
}
int main()
{
    f>>n;
    for(i=0;i<=25;++i)
    v.push_back(0);
    for(i=1;i<=n;++i)
    {
        f>>(s+1);
        m=strlen(s+1);
        for(j=0;j<=25;++j)
        v[j]=0;
        for(j=1;j<=m;++j)
        ++v[s[j]-'a'];
        has=0;
        for(j=0;j<=25;++j)
        has=(has*B+v[j])%MOD;
        if(exista(has))
        update(has);
        else
        adauga(has);
    }
    for(i=0;i<MOD;++i)
    sol+=decatunu(i);
    g<<sol<<'\n';
    return 0;
}