Poj-2503-Babelfish-dictionary tree

Source: Internet
Author: User

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 ;}
   
  
 


 

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.