Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/ABC-problem/PHP/abc-problem.php
Normal file
29
Task/ABC-problem/PHP/abc-problem.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
$words = array("A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "Confuse");
|
||||
|
||||
function canMakeWord($word) {
|
||||
$word = strtoupper($word);
|
||||
$blocks = array(
|
||||
"BO", "XK", "DQ", "CP", "NA",
|
||||
"GT", "RE", "TG", "QD", "FS",
|
||||
"JW", "HU", "VI", "AN", "OB",
|
||||
"ER", "FS", "LY", "PC", "ZM",
|
||||
);
|
||||
|
||||
foreach (str_split($word) as $char) {
|
||||
foreach ($blocks as $k => $block) {
|
||||
if (strpos($block, $char) !== FALSE) {
|
||||
unset($blocks[$k]);
|
||||
continue(2);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($words as $word) {
|
||||
echo $word.': ';
|
||||
echo canMakeWord($word) ? "True" : "False";
|
||||
echo "\r\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue