标签:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; struct node { node* next[26]; int num; node() { for(int i = 0;i<26;i++) next[i] = NULL; num = 0; } }; node* root = new node(); char s[15]; void insert() { int i,l = strlen(s); node* k = root; for(i = 0;i<l;i++) { int id = s[i]-‘a‘; if(k->next[id] == NULL) { node* t = new node(); k->next[id] = t; } k = k->next[id]; k->num++; } } int find() { int i,l = strlen(s); node* k = root; for(i = 0;i<l;i++) { int id = s[i]-‘a‘; if(k->next[id] == NULL) return 0; else k = k->next[id]; } return k->num; } int main() { bool b = 0; while(gets(s)) { if(s[0] == ‘\0‘) break; insert(); } while(scanf("%s",s)!=EOF) printf("%d\n",find()); return 0; }
一定要用C++交,G++嘎巴就MLE,然后发现网上的代码都MLE突然就释然了,改C++就过了
标签:
原文地址:http://www.cnblogs.com/wos1239/p/4387391.html