fork(1) download
  1. <?php
  2.  
  3. function doKstring($string, $s)
  4. {
  5.  
  6. $noAnsw = "Sorry, your string is invalid\n";
  7. $letters = preg_split("//u", $string, null, PREG_SPLIT_NO_EMPTY);
  8. foreach ($letters as $number => $letter) {
  9.  
  10.  
  11. $key = array_keys($letters, $letter);
  12. if (count($key) != $s) {
  13.  
  14. return $noAnsw;
  15.  
  16. }
  17. }
  18. sort($letters);
  19. $word = $letters[0];
  20. for ($i = 1; $i <= $s; $i++) {
  21.  
  22. $key = $i * $s;
  23.  
  24. $word .= $letters[$key];
  25. }
  26. $newString = $word;
  27. for ($i = 1; $i <= $s; $i++) {
  28. $new_string .= $word;
  29. }
  30.  
  31. return $new_string . "\n";
  32. }
  33. print_r(doKstring(авароыафвоыф, 4));
  34. print_r(doKstring(абвавбабв, 3));
  35. print_r(doKstring(ахкаахкхк, 3));
  36. print_r(doKstring(авбубббуааввууав, 4));
Success #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
Sorry, your string is invalid
абвабвабв
акхакхакх
абвуабвуабвуабву
stderr
PHP Notice:  Use of undefined constant авароыафвоыф - assumed 'авароыафвоыф' in /home/Nq1VYY/prog.php on line 34
PHP Notice:  Use of undefined constant абвавбабв - assumed 'абвавбабв' in /home/Nq1VYY/prog.php on line 35
PHP Notice:  Undefined offset: 9 in /home/Nq1VYY/prog.php on line 25
PHP Notice:  Undefined variable: new_string in /home/Nq1VYY/prog.php on line 29
PHP Notice:  Use of undefined constant ахкаахкхк - assumed 'ахкаахкхк' in /home/Nq1VYY/prog.php on line 36
PHP Notice:  Undefined offset: 9 in /home/Nq1VYY/prog.php on line 25
PHP Notice:  Undefined variable: new_string in /home/Nq1VYY/prog.php on line 29
PHP Notice:  Use of undefined constant авбубббуааввууав - assumed 'авбубббуааввууав' in /home/Nq1VYY/prog.php on line 37
PHP Notice:  Undefined offset: 16 in /home/Nq1VYY/prog.php on line 25
PHP Notice:  Undefined variable: new_string in /home/Nq1VYY/prog.php on line 29