SHARE
TWEET

Untitled

a guest Dec 30th, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. $command = readline();
  5.  
  6. $followersLikesComm = [];
  7. // $followersLikesComm[$username][0] - index 0 is likes count
  8. // $followersLikesComm[$username][1] - index 1 is comments count
  9.  
  10. while($command != "Log out")
  11. {
  12.     $cmds = explode(': ', $command);
  13.     $mainCmd = $cmds[0];
  14.     $username = $cmds[1];
  15.  
  16.     switch ($mainCmd)
  17.     {
  18.         case "New follower":
  19.             if(!key_exists($username, $followersLikesComm))
  20.             {
  21.                 $followersLikesComm[$username] = [0,0];
  22.                 // $followersLikesComm[$username][0] - index 0 is likes count
  23.                 // $followersLikesComm[$username][1] - index 1 is comments count
  24.             }
  25.             break;
  26.         case "Like":
  27.             $count = $cmds[2];
  28.             if(!key_exists($username, $followersLikesComm))
  29.             {
  30.                 $followersLikesComm[$username] = [$count,0];
  31.             }
  32.             else
  33.             {
  34.                 $followersLikesComm[$username][0] += $count;
  35.             }
  36.             break;
  37.         case "Comment":
  38.             if(!key_exists($username, $followersLikesComm))
  39.             {
  40.                 $followersLikesComm[$username] = [0,1];
  41.             }
  42.             else
  43.             {
  44.                 $followersLikesComm[$username][1] += 1;
  45.             }
  46.             break;
  47.         case "Blocked":
  48.             if(!key_exists($username, $followersLikesComm))
  49.             {
  50.                 echo "$username doesn't exist." . PHP_EOL;
  51.             }
  52.             else
  53.             {
  54.                 unset($followersLikesComm[$username]);
  55.             }
  56.             break;
  57.     }
  58.  
  59.     $command = readline();
  60. }
  61.  
  62. $followersLikes = [];
  63. $followersComments = [];
  64.  
  65. foreach ($followersLikesComm as $follower => $arr)
  66. {
  67.     $followersLikes[$follower] = $arr[0];
  68. }
  69.  
  70. foreach ($followersLikesComm as $follower => $arr)
  71. {
  72.     $followersComments[$follower] = $arr[1];
  73. }
  74.  
  75. ksort($followersLikes);
  76. arsort($followersLikes);
  77.  
  78. $count = count($followersLikes);
  79. echo $count . " followers" . PHP_EOL;
  80.  
  81. foreach ($followersLikes as $key => $val)
  82. {
  83.     echo $key . ": " . ($followersComments[$key] + $val) . PHP_EOL;
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top