Title Link: http://poj.org/problem?id=2503
Test instructions: Translated words, if not found in the dictionary output eh.
Idea: a bare dictionary tree.
Code:
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include < algorithm> #include <string> #include <vector>using namespace std; #define Lson L, M, RT << 1#define RS On M + 1, R, RT << 1 | 1#define ceil (x, Y) (((x) + (y)-1)/(y)) const int SIZE = 30;const int N = 3e6 + 10;const int INF = 0x7f7f7f7f;const int Max_word = 30;const int M = 1e5 + 10;struct Trie {int w;int val[size];}; int sz; Trie Pn[n];char Word[m][max_word];int newnode () {memset (pn[sz].val, 0, sizeof (pn[sz].val));p N[SZ].W = 0;return sz++;} void init () {sz = 0;newnode (); strcpy (word[0], "eh");} void Insert (char *s, int t) {int u = 0;for (int i = 0; s[i]; i++) {int idx = s[i]-' a '; if (!pn[u].val[idx]) Pn[u].val[idx] = NewNode (); u = Pn[u].val[idx];} PN[U].W = t;} int findstr (char *s) {int u = 0;for (int i = 0; s[i]; i++) {int idx = s[i]-' a '; if (!pn[u].val[idx]) return 0;u = Pn[u].va L[IDX];} return PN[U].W;} int main () {char S[max_word], t[max_word];init (); int i_n = 1;while (gets (s) && s[0]! = ' n ') {int k = 0;bool flag = false;for (int i = 0; s[i]; i++) {if (flag) t[k++] = S[i];if (s[i] = = ") {S[i] = ' + '; flag = True;}} T[k] = ' + '; Insert (t, i_n); strcpy (word[i_n++], s);} while (gets (s)) puts (WORD[FINDSTR (s)]); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2503 Babelfish (dictionary tree)