Poj-2503-Babelfish-dictionary tree
// Make several trie statements to draw a conclusion that, when the word length exceeds 15, it is suitable for hash, and no more than 15 times, it is suitable for trie ,,,, // because the constants of trie are mainly multiplied by the cycle of the word length, and the constants of hash in this cycle are basically 1 ,,, however, in addition to hash, conflicts need to be processed. The longer the word, the less likely it is to be sent into a conflict, and the shorter the time it takes to resolve the conflict ,,,, // trie has a hidden danger, if it is easy to time out with dynamic memory, with static memory easy super memory // http://blog.csdn.net/whyorwhnt/article/details/8723737#include
# Include
# Include
# Define deusing namespace std; struct node {char word [15]; // The int next [30];} tire [100005*15]; int e; void insert (char s [], char ch []) {int t = 0; for (int I = 0; ch [I]; I ++) {if (tire [t]. next [ch [I]-'a'] = 0) {tire [t]. next [ch [I]-'a'] = ++ e;} t = tire [t]. next [ch [I]-'a'];} strcpy (tire [t]. word, s) ;}void output (char str []) {int t = 0; for (int I = 0; str [I]; I ++) {if (tire [t]. next [str [I]-'a'] = 0) {printf (eh); return;} t = tire [t]. next [str [I]-'a'];} printf (% s, tire [t]. word);} int main () {char ch [30], str1 [15], str2 [15]; e = 1; // freopen(read.txt, r, stdin ); // memset (next, 0, sizeof (next); while (gets (ch) {if (ch [0] = 0) break; sscanf (ch, % s, str1, str2); insert (str1, str2) ;}while (gets (ch) {output (ch) ;}return 0 ;}