标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 41263 | Accepted: 17561 |
dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay
cat eh loops
1 //2016.9.4 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <cstring> 6 #include <map> 7 #define N 100005 8 9 using namespace std; 10 11 char s1[N][12], s2[N][12], str[25]; 12 map<long long, int> Hash; 13 14 long long F(char* s)//把字符串hash成一个26进制数 15 { 16 int len = strlen(s); 17 long long h = 0; 18 for(int i = 0; i < len; i++) 19 h = h*26+(s[i]-‘a‘); 20 return h; 21 } 22 23 int main() 24 { 25 int cnt = 0; 26 while(gets(str)) 27 { 28 if(str[0] == ‘\0‘)break; 29 sscanf(str,"%s%s", s1[cnt], s2[cnt]); 30 long long h = F(s2[cnt]); 31 Hash[h] = cnt; 32 cnt++; 33 } 34 while(gets(str)) 35 { 36 if(str[0] == ‘\0‘)break; 37 long long h = F(str); 38 if(Hash.find(h)!=Hash.end())//map按key查找,失败返回end 39 printf("%s\n", s1[Hash[h]]); 40 else printf("eh\n"); 41 } 42 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5839899.html