"uva644"immediate decodability (Trie

Source: Internet
Author: User

Test Instructions Translation

There are multiple sets of data in the subject. Each set of data gives a string containing only ' 0 ' and ' 1 ' at the end of "9", if there is another substring in it, output "set &case is not immediately decodable", otherwise output "set & Case is immediately decodable ". NewLine. The case is counted starting from 1.

Thank @fuko_ibuki for the translation

Title Description

Pdf

Input/output format Input Format:

output Format:

Input/Output sample Input Sample # #:Copy
0110001000009011001000009
Sample # # of output:Copy
Set 1 is immediately decodableset 2 are not immediately decodable
Exercises

It's a relatively simple trie question.

First, because lazy special handling, first ordered by length, and then from small to large enumeration of each string, and at the end of marking.

If a marked point is passed, the previous string is the prefix.

1 /*2 Qwerta3 UVA644 Immediate decodability4 Accepted5 Code C++,0.99KB6 Submission Time 2018-10-19 15:04:587 time consuming/memory8 50ms, 0KB9 */Ten#include <algorithm> One#include <iostream> A#include <cstring> -#include <cstdio> - using namespacestd; the strings[ One]; - BOOLcmpstringQaq,stringqwq) { -     returnQaq.length () <qwq.length (); - } + structemm{ -     intnxt[2],tag; +}a[ the]; A intMain () at { -     //freopen ("a.in", "R", stdin); -     intt=0; -      while(++t&&cin>>s[1]) -     { -         intn=1; in          Do{if(s[n][0]=='9') Break; -} while(cin>>s[++n]); ton--; +Sort (s+1, s+n+1, CMP); -         intCnt=0; theMemset (A,0,sizeof(a)); *         intflag=0; $          for(intC=1; c<=n&&!flag;++c)Panax Notoginseng         { -             intk=0; the              for(intI=0; I<s[c].length (); + +i) +             { A                 if(!a[k].nxt[s[c][i]-'0']) thea[k].nxt[s[c][i]-'0']=++CNT; +k=a[k].nxt[s[c][i]-'0']; -                 if(A[k].tag) flag++; $             } $a[k].tag=1; -         } -         if(!flag) theprintf"Set%d is immediately decodable\n", T); -         ElseWuyiprintf"Set%d is not immediately decodable\n", T); the     } -     return 0; Wu}

"uva644"immediate decodability (Trie

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.