Cod sursa(job #1668125)

Utilizator SilviuIIon Silviu SilviuI Data 29 martie 2016 16:19:09
Problema Restante Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <stdio.h>
#include <cstring>
#define mod 666013
#define p 256

using namespace std;

int n,nr;
int fr[26];
char s[26];
unsigned char hash1[mod+10];

int main()
{
    freopen("restante.in","r",stdin);
    freopen("restante.out","w",stdout);

    scanf("%d ",&n); int nr=0;

    for (int i=1;i<=n;i++) {
        memset(fr,0,sizeof(fr));
        gets(s+1); int m=strlen(s+1);

        for (int j=1;j<=m;j++) fr[s[j]-97]++;

        int curenthash=0;

        for (int j=0;j<26;j++) curenthash=(curenthash*p+fr[j])%mod;

        if (hash1[curenthash]==0) nr++;
        if (hash1[curenthash]==1) nr--;

        if (hash1[curenthash]==0) hash1[curenthash]=1; else
            hash1[curenthash]=2;

    }

    printf("%d",nr);

    return 0;
}