POJ 2503 Babelfish (dictionary tree)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.