Guest User

Untitled

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php
  2.   $fileout = fopen("output.txt","w");
  3.   $arra = file("input.txt");
  4.   $n = array_shift($arra);
  5.   for($i = 0; $i < $n; $i++){
  6.     if (preg_match("/".$arra[$i][0]."{".(int)$n."}/", $arra[$i])){
  7.       $answer[] = $arra[$i][0];
  8.     }
  9.   }
  10.   if (!count($answer)){
  11.     for($i = 0; $i < $n; $i++){
  12.       $cur='';
  13.       for($j = 0; $j < $n; $j++){
  14.         $cur=$cur.$arra[$j][$i];
  15.       }
  16.       if (preg_match("/".$cur[0]."{".(int)$n."}/", $cur)){
  17.         $answer[] = $cur[0];
  18.       }
  19.     }
  20.   }
  21.   if (!count($answer)){
  22.     fwrite($fileout, 'NO');
  23.   } else {
  24.     sort($answer, SORT_STRING);
  25.     fwrite($fileout, implode("", array_unique($answer)));
  26.   }
  27. ?>
Add Comment
Please, Sign In to add comment