萌新刚学oi,不懂为何re求教

P2580 于是他错误的点名开始了

~~不要脸~~
by nbhsy @ 2018-12-04 13:51:51


感觉错误有点多 改对了的版本: ```cpp #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <cctype> using namespace std; struct TRIE { int book; TRIE *_next[26]; TRIE() { book= 0; memset(_next, NULL, sizeof(_next)); } } root; void Insert(char *ch) { TRIE *t= &root; for(int i= 0; i < (int)strlen(ch); i++) { int id= ch[i] - 'a'; if(t->_next[id] != NULL) t= t->_next[id]; else { TRIE *q= new TRIE(); t->_next[id]= q; t= q; } } t->book= 1; } void Check(char *ch) { TRIE *t= &root; for(int i= 0; i < (int)strlen(ch); i++) { int id= ch[i] - 'a'; if(t->_next[id]) t= t->_next[id]; else { printf("WRONG\n"); return; } } if(!t->book) { printf("WRONG\n"); } else if(t->book == 1) { t->book= 2; printf("OK\n"); } else if(t->book == 2) { printf("REPEAT\n"); } return; } int main() { int T; scanf("%d", &T); while(T--) { char a[50]; scanf("%s", a); Insert(a); } scanf("%d", &T); while(T--) { char a[50]; scanf("%s", a); Check(a); } return 0; } ```
by Ciyang @ 2018-12-04 14:01:19


感觉你的Check写的有点问题,并且数组数值下标应该是从0开始啊 还有一个致命问题就是 \*root 都是NULL,访问绝对RE吧
by Ciyang @ 2018-12-04 14:04:34


根据一般的命名规范,没有特殊情况下所有类名第一个字母应大写,其它字母除了为了表示单词间隔的位置均应小写,所有函数名和变量名应全部小写。您的代码严重不符合命名规范,我看着不爽。
by chenkuowen01 @ 2018-12-04 14:05:59


**红名萌新??** 我自闭了
by Uni_Tune @ 2018-12-04 14:06:11


@[Ciyang](/space/show?uid=109815) 学习到了!谢谢!
by CloudStroll @ 2018-12-07 21:53:11


@[chenkuowen01](/space/show?uid=115133) 个人喜好,也许是该改改我诡异的码风。。
by CloudStroll @ 2018-12-07 21:53:39


|