Answer the question
In order to leave comments, you need to log in
Given 2 words, determine whether it is possible to make a 2nd word from the 1st word, provided that each letter from string 1 can be used only once?
hello, i can't figure out what to do next
<form action="" method="post">
<br>
<input type="text" name="first" autofocus="" placeholder="Первое слово">
<input type="text" name="second" placeholder="Второе слово">
<input type="submit" name="">
</form>
<?php
$first = $_POST["first"];
$lenghtF = iconv_strlen($first);
$second = $_POST["second"];
$lenghtS = iconv_strlen($second);
empty($first) && empty($second) ? exit : '';
for ($i=0; $i <= $lenghtF; $i++ )
{
echo $first[$i];
}
echo "<br /><br />";
for ($i=0; $i <= $lenghtS; $i++ )
{
echo $second[$i];
}
echo "<br /><br />";
for ($i = 0; $i <= $lenghtF; $i++)
{
for($j=0; $j <= $lenghtS; $j++)
{
if ($first[$i] == $second[$j])
printf("Буква из слова '%s'подходит к слову '%s' <br />",$first,$second);
else
printf("Не подходит<br />");
}
// $smb = strpos($first, $second[$i]); // ищем в "почве" нужный нам символ
// $smb ? $check .= $second[$i] : print("$second[$i] !-> $first<br />"); // создаем из символов слово (для проверки)
// $first[$smb] = ''; // удаляем символ, который нашли из нашей "почвы"
}
strcasecmp($second, $check) != 0 ? print("слово " . $second . " не подходит") : print("слово " . $second . " подходит");
?>
Answer the question
In order to leave comments, you need to log in
Given 2 words, determine whether it is possible to make 2 words from 1, provided that each letter from string 1 can be used only once?If this is read as "determine whether the first word can be made into a second", then the algorithm is simple:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question