PHP Solution: Baidu star----idiom error correction ____php

Source: Internet
Author: User
Tags parse string first row

1. Idiom Error correction (15 points)

Problem Background

Idioms are the cultural treasures of the Chinese nation, as a microcosm of history, the crystallization of wisdom, the essence of Chinese language, flashing a bright light.

Your task is to correct the wrong four-word idiom and find it correctly. Specifically, you are only allowed to modify one of the four Chinese characters so that the modified idiom appears in the given list of idioms. The original error idiom guarantees that it does not appear in the list of idioms.

Sometimes, such "error-correcting" results are not unique. For example, "a waxy daughter" can be changed to "profusely" can also be changed to "promise". But because "glutinous" and "Connaught" is a homonym word, "a waxy daughter" is actually "promise" the possibility is relatively big.

Therefore, we will also provide a Chinese character classification table, requiring that the two words before and after the modification must belong to the same classification.

Under such restrictions, we guarantee that idioms are the only result of error correction.

Attention

1, Chinese characters are used GBK code (see FAQ)

2, each Chinese character classification contains at least two Chinese characters, the same Chinese character may appear in many categories.

3, idioms in the list of idioms are the real existence of the four-word idiom. All the Chinese characters in the idiom list and the idiom to be corrected appear in at least one category in the Chinese character classification table.

Input Format

Enter the first row contains two integers n,m (1<=n<=200,1<=m<=20000). n represents the number of categories of Chinese characters, and M represents the number of idioms.
The following n lines each line uses a string of Chinese characters without a blank separator (space, TAB) to represent all the characters in a category. Note that the Chinese character string may contain up to 200 characters.

The following M-Act idiom list, each line an idiom, exactly four characters.

The last act to correct the idiom, exactly four characters, and does not appear in the list of idioms.

output Format

Only one line, for a four-word idiom. Under the "Modify must be done in the same classification" limit, the input data guarantees that the error-correcting results are unique.

Sample Input

73

Nuo nuo move

Purple seeds of the character Zi

Front money thousand lead shallow

In the near this present only tight gold Jin Jin to make the effort

End million

Water Sleeping Tax

Shan Flash shirt Good fan fir

Promise

Profusely

Lakes

A waxy daughter

Sample output

Promise

Basic method: The wrong idiom and the idiom array of each idiom comparison, when encountered a word not at the same time, to classify the judgment, if in the same category, output this modification

PHP Code:

<?php
Parse string to pay in English, become character array, get length
$fustr = ' DDDDDDDDDDDDDGDG major shareholder in Guangdong ';//parsed string
function Str_arr ($fustr, $mudi =1)
{$wz = 0;
$arr =array ();
while ($wz <strlen ($fustr)) {
$zifu = $fustr [$WZ];
if (Ord ($zifu) >127) {$str = $zifu. $fustr [$wz +1]; $wz = $wz +2;}

else{$str = $zifu; $wz + +;}

$arr []= $str;//put into an array

}//end while ($wz <strlen ($FUSTR))
if ($mudi ==1) return $arr;
else return count ($arr);
}
Test
$arr =str_arr ($fustr, $mudi =1);
Print_r ($arr);

End parsing string

Intercept function, intercept string array, get partial string
$arr =array ();//Array of strings
$ks =0;//intercept Start position
$long =10;//intercept length, how many characters

function jiequ ($arr, $ks, $long =0) {
if ($ks + $long >count ($arr)) return false;
$str = ';
$maxlen =count ($arr);
if ($long ==0) $end = $maxlen;
else $end = $ks + $long;
for ($i = $ks; $i < $end; $i + +) {
$str. = $arr [$i];
}

return $str;

}


Idiom Error correction
$cengyu =array (' promise ', ' profusely ', ' the vast ');//idiom array
$cuoci = ' One son of daughter ';//Wrong idiom, you need to change the wrong word correctly.
$fenlei =array (' Nuo nuo Noah ', "Zi purple seeds of the word, ' Qian Qian lead shallow ', ' in the near today only tight gold Jin Jin ', ' End million ', ' water sleep tax ', ' Mountain flash shirt good fan fir ');//Sort array

$arr 1=str_arr ($CUOCI);//an array that resolves to words
Iterate through the idiom array, find the correct idiom, make the change
for ($i =0; $i <count ($cengyu); $i + +) {
$arr 2=str_arr ($cengyu [$i]);
$butong different numbers of =0;//
$jishu = 0;
There are several different statistics, passing one, then you can modify
For ($i 1=0 $i 1<4; $i 1++) {
if ($butong >=2) break;

if ($arr 1[$i 1]== $arr 2[$i 1]) $jishu + +;
else {$butong + +; $index = $i 1;}


}//end for ($i 1=0; $i 1<4; $i 1++)

Judging by the number of different, passing 1, then need to judge whether the same
if ($butong ==1) {
$zi 1= $arr 1[$index];
$zi 2= $arr 2[$index];
To judge whether the same
$tonglei = 0;
for ($i 2=0; $i 2<count ($fenlei); $i 2++) {
if (Strpos ($fenlei [$i 2], $zi 1)!==false&&strpos ($fenlei [$i 2], $zi 2)!==false) {

$tonglei = 1;
Break
}

}//end for ($i 2=0; $i 2<count ($fenlei)
if ($tonglei ==1) {echo $cuoci. $zi 1. "Instead of: '. $zi 2. ', the correct idiom is: '. $cengyu [$i]. ' <br> ';

Break
}//end if ($tonglei ==1) {

}//end if ($butong ==1)

}//end for ($i =0; $i <count ($cengyu);

?>

Related Article

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.