Baidu Star Programming Competition - Language Translation Machine (C # Solution)

xiaoxiao2021-04-07  353

Even C forgotten for many years, or use C # to edit one, huh, huh

1. Baidu language translator Baidu engineers are very payment of efficiency, in the long-term development and testing process, they gradually created a unique abbreviation. They are in the usual conversation, conference, and even in various technical documents.

In order to make new employees can adapt to Baidu culture more quickly, better reading the company's technical documentation, the Human Resources Department decided to develop a special translation system, translate the abbreviations and proprietary nouns in related documents into the daily language.

Enter the requirements: Input data contains three parts: 1. The first line contains an integer N (n <= 10000), indicating how many abbreviations have a total of more abbreviations; 2. Follow the input of N rows, each line contains two Strings, separated by spaces. The first string is abbreviated (only uppercase English characters, no more than 10 bytes of length), the second string is the daily language (not including spaces, no more than 255 bytes); 3. From Night 2 Start to the input end to the related document containing the abbreviation (the total length does not exceed 10,000 bytes). Example: 6 PS Portal Search Department NLP Natural Language Processing PM Product Marketing HR HR PMD Product Promotion Department MD Market Development Department Baidu sectors include PS, PM, HR, PMD, MD, etc., where PS also includes NLP groups. Sample: in.txt

Output requirements: Output converts abbreviations into daily language documents. (Convert the abbreviation into a daily language, other characters are retained). Example: Baidu's department includes portal search units, product market portions, human resources department, product promotion, market development department, etc., where the portal search unit also includes a natural language processing team. Sample: OUT.TXT

Rules: 1. The program will run on a Linux machine (memory usage is not strictly limited), and it cannot be more than 10 seconds in each test case, otherwise the usage case is unable; 2. The program is required to read the data file in the form of the input sample, and the run results are output to the standard output according to the format of the output sample. If data and output data cannot be read correctly, the title will not be scored; 3. The topic has 4 test cases, each test case for an input file. The ratio of each test case accounted for 25%, 25%, 25%, 25%, respectively; 4. The title is 20 points.

Note: 1. The input data is mixed in Chinese, and Chinese uses GBK coding. GBK: Yes, another Chinese character code standard, full name "Chinese Character Code Extension Specification". With double-byte representation, the overall coding range is 8140-Fefe, and the first byte is between 81-Fe, the tail byte is between 40-Fe, excludes XX7F. Total 23940 code bits, total income of 21,886 Chinese characters and graphics symbols, including 21003 Chinese characters (including ministries and components), and 883 graphics symbols.

2. In order to ensure the uniqueness of the answer, the transformation of abbreviations uses the principle of maximum match (from left to right). Please pay attention to the translation of PMD in the sample.

// ***************************************************** / /

Using system; using system.text; using system.collections;

Namespace Baidutest1 {/ * Test questions See .txt document * / class class1 {///

///// [stathread] static void main (String [] Args) {translate translate (); transole.readinput (); console.write (); console.readline ()); console.readline ();}} class translate {static readonly string infilename = "in.txt"; // English and Chinese control static readonly string outfilename = "out.txt"; // To translate the paragraph HashTable htmap = new hashtable ();

public void ReadInput () {if (File.Exists (InFileName)) {string [] strSplit = null; string Input = string.Empty; using (StreamReader reader = new StreamReader (InFileName, Encoding.Default)) // Encoding.GetEncoding ("GB18030")); {while ((Input = Reader.Readline ())! = Null) {strsplit = INPUT.SPLIT (''); // Dividing IF in a space (strsplit.length == 2 && HTMap.Containskey (strsplit [0])) {htmap.add (strsplit [0], strsplit [1]);}}}}}

public string Output () {string txt = string.Empty; if (File.Exists (OutFileName)) {string Word = string.Empty; int nIndex = 0; using (StreamReader reader = new StreamReader (OutFileName, Encoding.Default)) {Txt = reader.readToEnd (); if (txt! = String.empty) {foreach (char chin txt) {if (ch> = 'a' && ch <= 'z') {Word = Word.Isert Word.Length, Ch.Tostring ());} else {if (Word.Length! = 0 && HTMap.Contains (Word)) {// Insert New Character, INDEX changes txt = txt.remove (Nindex - Word. Length, word.length; txt = txt.insert (nindex - word.length, htmap [word] .tostring ()); NINDEX = NINDEX - Word.Length HTMAP [Word] .tostring (). Length;} word = String.empty;}}}}}}}}}}}};

Source code download:

Http://www.s135.com/disk/down.php?user=iipauqpst &pass=rs^UV~]P `l^ &mid=1TbibqEWGEO9TS0ppqaasm% 250A5% 250A16539% 250A1 & Funcid = Readpart & Part = 3 & filename = baidutest1.rar

转载请注明原文地址:https://www.9cbs.com/read-132608.html

New Post(0)