这题目主要是难在字符串处理这块。
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #define mod 999983 5 struct node{ 6 char str[10+100]; 7 char res[10+100]; 8 node *next; 9 }p[mod]; 10 int sign[mod]; 11 void hash(char str[],char res[]){ 12 int i,l=strlen(str); 13 int key=0; 14 for(i=0;i<l;++i) key=(key+str[i]*str[i])%mod; 15 if(sign[key]==0){ 16 strcpy( p[key].str , str ); 17 strcpy( p[key].res , res ); 18 p[key].next=NULL; 19 sign[key]=1; 20 } else if( sign[key]==1 ){ 21 node *op=&p[key]; 22 while(op->next!=NULL) 23 op=op->next; 24 node *tmp=(node *)malloc(sizeof(node)); 25 strcpy( tmp->str,str ); 26 strcpy( tmp->res,res ); 27 tmp->next=NULL; 28 op->next=tmp; 29 } 30 return ; 31 } 32 node *find_hash(char str[]){ 33 int i,l=strlen(str); 34 int key=0; 35 for(i=0;i<l;++i) key=(key+str[i]*str[i])%mod; 36 if(sign[key]==0) return NULL; 37 else if(sign[key]==1){ 38 // printf("here! "); 39 node *op=&p[key]; 40 while(1){ 41 if(strcmp(str,op->str)==0) 42 return op; 43 if(op->next==NULL) break; 44 op=op->next; 45 } 46 } 47 return NULL; 48 } 49 50 int change(){ 51 char str[10+100]; 52 int l,i,j; 53 gets(str); 54 if(str[0]=='