Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. $n = 6;
  3. //инициализация
  4. $start = microtime(true);
  5.  
  6.  
  7. $arr = [
  8. 0=> "A",
  9. 1=> "Б",
  10. 2=> "В",
  11. 3=> "Г",
  12. 4=> "Д",
  13. 5=> "Е",
  14. 6=> "Ж",
  15. 7=> "З",
  16. 8=> "И",
  17. 9=> "К",
  18.  
  19. ];
  20.  
  21. function getChisloAndStr ($n)
  22. {
  23. $arr = [
  24. 0=> "A",
  25. 1=> "Б",
  26. 2=> "В",
  27. 3=> "Г",
  28. 4=> "Д",
  29. 5=> "Е",
  30. 6=> "Ж",
  31. 7=> "З",
  32. 8=> "И",
  33. 9=> "К",
  34.  
  35. ];
  36. $stroka = "";
  37. $chisla= "";
  38.  
  39. for ($i = 1; $i<= $n; $i++)
  40. {
  41. $temp = rand(0,9);
  42. $chisla .= $temp;
  43. $stroka .= $arr[$temp];
  44. }
  45. $chisla = intval ($chisla);
  46. $res [0] = $chisla;
  47. $res [1] = $stroka;
  48. return $res;
  49. }
  50.  
  51. $res1 = getChisloAndStr($n);
  52. $res2 = getChisloAndStr($n);
  53. $answerChislo = $res1[0]+$res2[0];
  54.  
  55.  
  56. $int = preg_split('//',$answerChislo);
  57. array_pop($int); array_shift($int);
  58.  
  59. $answerSTR = $res1[1]."+".$res2[1]."=";
  60. for ($i=0; $i<= mb_strlen($answerChislo)-1;$i++)
  61. {
  62. $answerSTR .= ($arr[$int[$i]]);
  63.  
  64. }
  65. printf($answerSTR."<br>");
  66. printf($res1[0]."+".$res2[0]."=".$answerChislo."<br>");
  67. $end = microtime(true);
  68. $time = $end - $start;
  69. printf('Время работы скрипта: %.7F сек.', $time);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement