Advertisement
MartinGeorgiev

02.Tasks

Jun 30th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. $tasks = array_map("intval", explode(" ", readline()));
  4.  
  5. $input = readline();
  6. while ($input !== "End") {
  7.     $args = explode(" ", $input);
  8.     $command = $args[0];
  9.     $index = $args[1];
  10.     switch ($command) {
  11.         case "Complete":
  12.             if ($index >= 0 && $index < count($tasks)) {
  13.                 $tasks[$index] = 0;
  14.             }
  15.             break;
  16.  
  17.         case "Drop":
  18.             if ($index >= 0 && $index < count($tasks)) {
  19.                 $tasks[$index] = -1;
  20.             }
  21.             break;
  22.         case "Change":
  23.             $time = intval($args[2]);
  24.             if ($index >= 0 && $index < count($tasks)) {
  25.                 $tasks[$index] = $time;
  26.             }
  27.             break;
  28.         case "Count":
  29.             $type = $args[1];
  30.             $droppedCount = 0;
  31.             $completeCount = 0;
  32.             $incompleteCount = 0;
  33.             for ($i = 0; $i < count($tasks); $i++) {
  34.                 $current = intval($tasks[$i]);
  35.                 if ($current < 0) {
  36.                     $droppedCount++;
  37.                 } else if ($current === 0) {
  38.                     $completeCount++;
  39.                 } else {
  40.                     $incompleteCount++;
  41.                 }
  42.             }
  43.             if ($type === "Dropped") {
  44.                 echo $droppedCount . PHP_EOL;
  45.             } else if ($type === "Completed") {
  46.                 echo $completeCount . PHP_EOL;
  47.             } else {
  48.                 echo $incompleteCount . PHP_EOL;
  49.             }
  50.             break;
  51.     }
  52.  
  53.  
  54.     $input = readline();
  55. }
  56. for ($i = 0; $i < count($tasks); $i++) {
  57.     if ($tasks[$i] > 0) {
  58.         echo "$tasks[$i] ";
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement