Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $fileout = fopen("output.txt","w");
- $arra = file("input.txt");
- $n = array_shift($arra);
- for($i = 0; $i < $n; $i++){
- if (preg_match("/".$arra[$i][0]."{".(int)$n."}/", $arra[$i])){
- $answer[] = $arra[$i][0];
- }
- }
- if (!count($answer)){
- for($i = 0; $i < $n; $i++){
- $cur='';
- for($j = 0; $j < $n; $j++){
- $cur=$cur.$arra[$j][$i];
- }
- if (preg_match("/".$cur[0]."{".(int)$n."}/", $cur)){
- $answer[] = $cur[0];
- }
- }
- }
- if (!count($answer)){
- fwrite($fileout, 'NO');
- } else {
- sort($answer, SORT_STRING);
- fwrite($fileout, implode("", array_unique($answer)));
- }
- ?>
Add Comment
Please, Sign In to add comment