Poj 2503 dictionary tree

Source: Internet
Author: User

This question was previously recorded in our weekly competition, and then we used map.

Because I want to talk about the dictionary tree to my freshman in the past two days, I have to practice a few pieces of code to prevent the freshman from being dizzy ......

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <map> # include <queue> # include <set> # include <cmath> # include <bitset> # define MEM (, b) memset (a, B, sizeof (A) # define lson I <1, L, mid # define rson I <1 | 1, Mid + 1, R # define INF 510010 # define maxn 400010 using namespace STD; typedef long ll; typedef unsigned long ull; int ch [maxn] [27]; // node number int SZ; // number of nodes in the dictionary tree int Val [maxn]; // The number of nodes Value. If it is 1, a new string char STR [maxn] [11] is added. Void Init () // initialization {SZ = 1; memset (CH, 0, sizeof (CH); memset (Val, 0, sizeof (VAL);} void insert (char * s, char * ss) {int u = 0, I, C, L = strlen (SS); for (I = 0; I <L; I ++) {c = ss [I]-'A'; If (! Ch [u] [c]) CH [u] [c] = SZ ++; u = CH [u] [c];} Val [u] = 1; strcpy (STR [u], S);} void query (char * s) {int u = 0, I, C, L = strlen (s), flag = 1; for (I = 0; I <L; I ++) {c = s [I]-'A'; If (! Ch [u] [c]) {flag = 0; break;} u = CH [u] [c];} If (Val [u] & flag) printf ("% s \ n", STR [u]); else puts ("eh");} int main () {char s [22], S1 [12], s2 [12]; Init (); While (gets (s), s [0]! = '\ 0') {int I, Len = strlen (s), j = 0, K = 0, flag = 1; for (I = 0; I <Len; I ++) {If (s [I]! = ''& Flag) S1 [J ++] = s [I]; else if (s [I]! = ''&&! Flag) S2 [k ++] = s [I]; else flag = 0;} S1 [J] = '\ 0'; S2 [k] =' \ 0 '; insert (S1, S2);} while (gets (s) query (s); Return 0 ;}


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.