Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $command = readline();
- $followersComments = [];
- $followersLikes = [];
- while($command != "Log out")
- {
- $cmds = explode(': ', $command);
- $mainCmd = $cmds[0];
- $username = $cmds[1];
- switch ($mainCmd)
- {
- case "New follower":
- if(!key_exists($username, $followersComments))
- {
- $followersComments[$username] = 0;
- $followersLikes[$username] = 0;
- }
- break;
- case "Like":
- $count = $cmds[2];
- if(!key_exists($username, $followersLikes))
- {
- $followersLikes[$username] = $count;
- }
- else
- {
- $followersLikes[$username] += $count;
- }
- break;
- case "Comment":
- if(!key_exists($username, $followersComments))
- {
- $followersComments[$username] = 1;
- }
- else
- {
- $followersComments[$username] += 1;
- }
- break;
- case "Blocked":
- if(!key_exists($username, $followersComments) && !key_exists($username, $followersLikes))
- {
- echo "$username doesn't exist." . PHP_EOL;
- }
- else
- {
- if(key_exists($username, $followersComments))
- {
- unset($followersComments[$username]);
- }
- if(key_exists($username, $followersLikes))
- {
- unset($followersLikes[$username]);
- }
- }
- break;
- }
- $command = readline();
- }
- $totalFollowers = [];
- $follCommentsAndLikes = [];
- foreach ($followersComments as $follower => $value)
- {
- if(!in_array($follower, $totalFollowers))
- {
- $totalFollowers[] = $follower;
- }
- $follCommentsAndLikes[$follower]['C'] = $value;
- }
- foreach ($followersLikes as $follower => $value)
- {
- if(!in_array($follower, $totalFollowers))
- {
- $totalFollowers[] = $follower;
- }
- $follCommentsAndLikes[$follower]['L'] = $value;
- }
- echo count($totalFollowers) . " followers" . PHP_EOL;
- $follCommentsAndLikes = array_filter($follCommentsAndLikes);
- print_r($follCommentsAndLikes);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement