Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. //$numberOne = intval(fgets(STDIN));
  4. //$numberTwo = intval(fgets(STDIN));
  5.  
  6. $numberOne = "hi php java csharp sql html css js";
  7. $numberTwo = "hi php java js softuni nakov java learn";
  8.  
  9.  
  10. $lenght = min(strlen($numberOne), strlen($numberTwo));
  11. $maxCount = 0;
  12. $endIndex = 0;
  13.  
  14. for ($i = 0; $i < $lenght; $i++) {
  15.     $count = 0;
  16.     $element = $i;
  17.  
  18.     while ($numberOne[$i] == $numberTwo[$i]) {
  19.         $count++;
  20.         $element++;
  21.         if ($element = $lenght) {
  22.             break;
  23.         }
  24.     }
  25.     if ($count > $maxCount) {
  26.         $maxCount = $count;
  27.         $endIndex = $element - 1;
  28.     }
  29.     if ($count > 0) {
  30.         $i += $count - 1;
  31.     }
  32. }
  33. reverse($numberOne);
  34. reverse($numberTwo);
  35.  
  36. for ($i = 0; $i < $lenght; $i++) {
  37.     $count = 0;
  38.     $element = $i;
  39.  
  40.     while ($numberOne[$i] == $numberTwo[$i]) {
  41.         $count++;
  42.         $element++;
  43.         if ($element = $lenght) {
  44.             break;
  45.         }
  46.     }
  47.     if ($count > $maxCount) {
  48.         $maxCount = $count;
  49.         $endIndex = $element - 1;
  50.     }
  51.     if ($count > 0) {
  52.         $i += $count - 1;
  53.     }
  54. }
  55.  
  56. function reverse($string)
  57. {
  58.  
  59.     for ($i = 0; $i < strlen($string) / 2; $i++) {
  60.         $tmp = $string[$i];
  61.         $string[$i] = $string[strlen($string) - $i - 1];
  62.         $string[strlen($string) - $i - 1] = $tmp;
  63.     }
  64. }
  65.  
  66. echo $maxCount;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement