Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求助,hash过不了

Posted by 1916437702 at 2022-12-24 00:30:22 on Problem 2503
#include<stdio.h>
#include<string.h>
#define mm 100000
struct hash1{
    char s[11];
    int key;
}h[mm];

unsigned long long hash(char * str){
    unsigned long long ans=0,i=0;
    while(str[i]!=0){
        ans = ans * 26;
        ans += str[i]-'a'+1;
        ans = ans%13546+1;
        i++;
    }
    ans = ans%123546+6;
    return ans;
}


int main()
{
    char str[25],str1[11],str2[11];
    int a;
    while(gets(str)!=NULL&&str[0]!='\0')
    {
        sscanf(str,"%s %s",str1,str2);
        a=hash(str2);
        h[a].key=1;
        strcpy(h[a].s,str1);
    }
    
    while(gets(str)){
        int i=hash(str);
        if(h[i].key==1)
        printf("%s\n",h[i].s);
        else printf("eh\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator