Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $firstString = explode(" ", trim(fgets(STDIN)));
- $secondString = explode(" ", trim(fgets(STDIN)));
- $rightCount = 0;
- $leftCount = 0;
- $shorter = min(count($firstString), count($secondString));
- while ($rightCount < count($firstString) && $rightCount < count($secondString)) {
- if ($firstString[count($firstString) - $rightCount - 1] == $secondString[count($secondString) - $rightCount - 1]) {
- $rightCount++;
- }
- else break;
- }
- while ($leftCount < count($firstString) && $leftCount < count($secondString)) {
- if ($firstString[$leftCount] == $secondString[$leftCount]) {
- $leftCount++;
- }
- else break;
- }
- if ($rightCount > $leftCount) {
- echo $rightCount;
- } else {
- echo $leftCount;
- }
- ?>
Add Comment
Please, Sign In to add comment