Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 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