Xiaodi
Some people know how to break ce when SZ = 1 is added to trie ??? Can someone teach me ?? I still don't know how C ++ is weak. Thank you very much! Orz
# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <ctype. h> # include <math. h ># include <string >#include <iostream> # include <algorithm> using namespace STD; # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # define word_len 1000010 # define sigma_size 128 typedef struct trie {int ch [word_len] [sigma_size]; // word_len indicates the number of nodes in the dictionary tree. If all nodes are lowercase letters, sigma_size = 26 int have_word [word _ Len]; // There are several words in this node: int SZ; trie () {// here !!!~~~~~ Memset (CH, 0, sizeof (CH); memset (have_word, 0, sizeof (have_word) ;}; trie AC; int tol; void insert (char * s) // Add the V number to the last letter of the S word {int u = 0, Len = strlen (s); For (INT I = 0; I <Len; I ++) {int c = s [I]; If (! AC. ch [u] [c]) // If the node does not exist, add the AC after the node is created. ch [u] [c] = ac. SZ ++; u = ac. ch [u] [c];} AC. have_word [u] ++; // The current U is the last position of the word} Char s [222]; void find (int x, int K) {for (INT I = 0; I <128; I ++) {If (AC. ch [x] [I]) {Int J = ac. ch [x] [I]; s [k] = I; If (AC. have_word [J]) {s [k + 1] = '\ 0'; printf ("% S %. 4lf \ n ", S, AC. have_word [J] * 100.0/TOL);} Find (j, k + 1) ;}} int main () {char C [222]; Tol = 0; AC. SZ = 1; while (gets (c) & C [0]) {insert (c); Tol ++;} Find (0, 0); Return 0 ;}
[Dictionary tree] poj 2418 Hardwood Species