The way of Garlic 2015 program Design Competition first game--Sogou Input method of Word segmentation algorithm

Source: Internet
Author: User

(i) the question surface

The way of Garlic 2015 program Design Competition first game--Sogou Input method of Word segmentation algorithm

Sogou Input Method recently appeared in the user input a new input mode, shaped like "0k1234567", Sogou engineers found that this model is known, this is a new proposed for the digital notation of the mark mode, where "0k" is a tag into the 15 prefix tag, after the section " 1234567 "is the actual number string of the XV binary.

After discovering this pattern, Sogou's engineers began to try to further add to the existing Word segmentation algorithm for the processing of the digital string, the 15 binary number of this form of the Web page is correctly extracted. We know that the mark "0k" in the "K" must be lowercase, the number 0 to 14 in this set of marked mode will be expressed in sequence: 0k0, 0k1, ..., 0k9, 0kA, 0kB, 0kC, 0kD, 0kE. This means that only 0-9, K, and A-e will appear in the 15 binary numbers.

It is important to note that there is no extra 0 in the number representation, such as 0k05, which cannot be used as a binary number. In addition, as a convention, when the "0k90k8" occurs, only the 0k90 is in line with the expected number of digits, that is, always from left to right in order to extract the longest number of XV. If you wish to express the ligatures of the two numbers of 0k9 and 0K8, it will be written in the form of "0k9 ' 0k8" (single quotes represent any other non-numeric characters).

Sogou engineers want to be in the user input in accordance with the above requirements of all the XV number of output in turn. Can you do it for him?

Input format

Enter a line of String str (1≤|str|≤106) to indicate the user input from the Sogou engineer. The characters in the user input must be numbers (0-9) or uppercase letters (A-Z, A-Z).

Output format

The output consists of several lines, each of which outputs an extracted XV number (in the form of: 0k1234), corresponding to the number of decimal digits in the input string that conform to the tag pattern, and output, in the order in which the numbers are in the original string.

Example 1

Input:

Sjfjfhua0ka0000lmnhdhahdfhggdjg90k10k110k120kf

Output:

0ka00000k110

(b) Reference to the source of the answer

1 ImportJava.io.BufferedReader;2 ImportJava.io.InputStreamReader;3 4  Public classMain {5     //Line_separator is equal to "\ r \ n" for Windows6     Private Static FinalString Line_separator =System7. GetProperty ("Line.separator");8     Private StaticBufferedReader reader =NewBufferedReader (9             NewInputStreamReader (system.in));Ten  One     /** A      *  - * Determine if the character character is a 16 binary character -      */ the     Static BooleanIS16 (Charcharacter) { -         if((character >= ' 0 ' && character <= ' 9 ') -|| (character >= ' A ' && character <= ' E ')) { -             return true; +         } -         return false; +     } A  at      Public Static voidMain (string[] args)throwsException { -  -         Char[] Inputarray =New Char[1000000]; -         //all the results to be output are put into the StringBuilder, and the last one is output at once. If each one is found, the output will affect the efficiency -StringBuilder Builder =NewStringBuilder (); -         //whether 16 binary numbers were found in         BooleanFound =false; -         //the number of characters in the input sequence, initialized to-1 to         intNumberofcharacter =-1; +         //Note: Method int Java.io.Reader.read (char[] cbuf) throws -         //The IOException is blocked when there is no input, so if you use while, you will not be running until the code that follows the while.  the         if((Numberofcharacter = Reader.read (inputarray))! =-1) { *              for(inti = 0; I <Numberofcharacter;) { $                 if(found) {Panax Notoginseng                     if(!is16 (Inputarray[i])) { - builder.append (line_separator); theFound =false; +i++; A}Else { the builder.append (Inputarray[i]); +i++; -                     } $}Else { $                     //here to determine whether I is less than numberOfcharacter-2, and consider the efficiency, as the last judgment condition of the IF statement.  -                     if(Inputarray[i] = = ' 0 ' && inputarray[i + 1] = = ' k ' -&& I < NumberOfcharacter-2) { the                         if(Inputarray[i + 2] = = ' 0 ') { -                             //ex:0k0WuyiBuilder.append ("0k0"). Append (line_separator); thei = i + 3; -}Else if(IS16 (Inputarray[i + 2])) { Wu                             //Ex:0k2 -Builder.append ("0k"). Append (Inputarray[i + 2]); AboutFound =true; $i = i + 3; -}Else { -                             //EX:0KF -i = i + 3; A                         } +}Else { thei++; -                     } $                 } the             } the  the         } the         if(Builder.length () > 0) { - System.out.println (builder.tostring ()); in         } the     } the}
View Code

The way of Garlic 2015 program Design Competition first game--Sogou Input method of Word segmentation algorithm

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.