fork download
  1. <?php
  2. class ProsteDodawanie{ //name easy sum
  3.  
  4. private $hi;
  5. private $ho;
  6.  
  7. private $x;
  8. private $y;
  9.  
  10. private $sum;
  11.  
  12. public function __construct(){
  13.  
  14. $this->hi = fopen('php://stdin', "r");
  15. $this->ho = fopen('php://stdout', "w");
  16. }
  17.  
  18. public function VariableOperations(){
  19. while($this->x = trim(fgets($this->hi))){
  20.  
  21. $this->y = explode(" ", $this->x);
  22.  
  23. $this->sum = 0;
  24.  
  25. for($i=0; $i<count($this->y); $i++){
  26. $this->sum += $this->y[$i];
  27. }
  28.  
  29. fwrite($this->ho, sprintf("%d\n", $this->sum)); //show sum
  30.  
  31. }
  32.  
  33. }
  34. public function __destruct(){
  35. fclose($this->ho);
  36. fclose($this->hi);
  37. }
  38. }
  39.  
  40. $test = new ProsteDodawanie;
  41. $test ->VariableOperations();
Success #stdin #stdout 0s 82560KB
stdin
2
5
1 2 3 4 5
2
-100 100
stdout
2
5
15
2
0