2012年4月11日

摘要: 今天在写程序时遇到的一个问题 #include <stdio.h> #include <string> using std::string; int main() { char str[STEL]; while (scanf("%s", str) && strcmp(str, "end")) { printf("%s = %u\n", str, hash(str)); } return 0; }写完用g++编译,出现error: ‘strcmp’ was not declared in this 阅读全文
posted @ 2012-04-11 16:25 aho 阅读(21568) 评论(0) 推荐(0) 编辑
摘要: #define NHASH 29989 //根据自己的实际需要来设置 #define MULT 31 unsigned int hash(char* p) { unsigned int h = 0; for ( ; *p; p++) { h = MULT * h + *p; } return h % NHASH; }本来我以为其中的31是为了将一个字符串,比如abc当做一个31进制的数字来看,但是考虑到26个英文字母再加上大写的情况,就是52个,跟31不沾边啊。留待思考! 阅读全文
posted @ 2012-04-11 11:21 aho 阅读(266) 评论(0) 推荐(0) 编辑

导航