字符串转hash

#include<bits/stdc++.h>
using namespace std;
unsigned hash[10];
const unsigned P=1000000007;
int ans;
int main()
{
    for(int k=1;k<=7;k++)
    {
        char s[105];
        scanf("%s",s);
        int len=strlen(s);
        hash[k]=0;
        for(int i=0;i<len;i++)
            hash[k]=hash[k]*P+s[i];
        ans++;
        for(int i=1;i<k;i++)
            if(hash[i]==hash[k])
            {
                ans--;
                break;    
            }            
    }    
    cout<<ans;
    return 0;
} 

 

posted @ 2019-08-13 14:57  DreamingBligo_Tido  阅读(815)  评论(0编辑  收藏  举报