Advertisement
whitestarrr

Untitled

Jan 31st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2.  
  3. $firstString = explode(" ", trim(fgets(STDIN)));
  4. $secondString = explode(" ", trim(fgets(STDIN)));
  5.  
  6. $rightCount = 0;
  7. $leftCount = 0;
  8.  
  9. $shorter = min(count($firstString), count($secondString));
  10.  
  11.  
  12. while ($rightCount < count($firstString) && $rightCount < count($secondString)) {
  13. if ($firstString[count($firstString) - $rightCount - 1] == $secondString[count($secondString) - $rightCount - 1]) {
  14. $rightCount++;
  15. }
  16. else break;
  17. }
  18.  
  19. while ($leftCount < count($firstString) && $leftCount < count($secondString)) {
  20. if ($firstString[$leftCount] == $secondString[$leftCount]) {
  21. $leftCount++;
  22. }
  23. else break;
  24. }
  25.  
  26. if ($rightCount > $leftCount) {
  27. echo $rightCount;
  28. } else {
  29. echo $leftCount;
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement