Advertisement
petar088

Untitled

Jun 6th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. Problem 9. * User Logs
  2. Marian is a famous system administrator. The person to overcome the security of his servers has not yet been born. However, there is a new type of threat where users flood the server with messages and are hard to be detected since they change their IP address all the time. Well, Marian is a system administrator and is not so into programming. Therefore, he needs a skillful programmer to track the user logs of his servers. You are the chosen one to help him!
  3. You are given an input in the format:
  4. IP=(IP.Address) message=(A&sample&message) user=(username)
  5. Your task is to parse the IP and the username from the input and for every user, you have to display every IP from which the corresponding user has sent a message and the count of the messages sent with the corresponding IP. In the output, the usernames must be sorted alphabetically while their IP addresses should be displayed in the order of their first appearance. The output should be in the following format:
  6. username:
  7. IP => count, IP => count.
  8. For example, given the following input - IP=192.23.30.40 message='Hello&derps.' user=destroyer, you have to get the username destroyer and the IP 192.23.30.40 and display it in the following format:
  9. destroyer:
  10. 192.23.30.40 => 1.
  11. The username destroyer has sent a message from IP 192.23.30.40 once.
  12. Check the examples below. They will further clarify the assignment.
  13. Input
  14. The input comes from the console as varying number of lines. You have to parse every command until the command that follows is end. The input will be in the format displayed above, there is no need to check it explicitly.
  15. Output
  16. For every user found, you have to display each log in the format:
  17. username:
  18. IP => count, IP => count…
  19. The IP addresses must be split with a comma, and each line of IP addresses must end with a dot.
  20. Constraints
  21. • The number of commands will be in the range [1..50]
  22. • The IP addresses will be in the format of either IPv4 or IPv6.
  23. • The messages will be in the format: This&is&a&message
  24. • The username will be a string with length in the range [3..50]
  25. • Time limit: 0.3 sec. Memory limit: 16 MB.
  26.  
  27. Examples
  28. Input Output
  29. IP=192.23.30.40 message='Hello&derps.' user=destroyer
  30. IP=192.23.30.41 message='Hello&yall.' user=destroyer
  31. IP=192.23.30.40 message='Hello&hi.' user=destroyer
  32. IP=192.23.30.42 message='Hello&Dudes.' user=destroyer
  33. end destroyer:
  34. 192.23.30.40 => 2, 192.23.30.41 => 1, 192.23.30.42 => 1.
  35. IP=FE80:0000:0000:0000:0202:B3FF:FE1E:8329 message='Hey&son' user=mother
  36. IP=192.23.33.40 message='Hi&mom!' user=child0
  37. IP=192.23.30.40 message='Hi&from&me&too' user=child1
  38. IP=192.23.30.42 message='spam' user=destroyer
  39. IP=192.23.30.42 message='spam' user=destroyer
  40. IP=192.23.50.40 message='' user=yetAnotherUsername
  41. IP=192.23.50.40 message='comment' user=yetAnotherUsername
  42. IP=192.23.155.40 message='Hello.' user=unknown
  43. end child0:
  44. 192.23.33.40 => 1.
  45. child1:
  46. 192.23.30.40 => 1.
  47. destroyer:
  48. 192.23.30.42 => 2.
  49. mother:
  50. FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1.
  51. unknown:
  52. 192.23.155.40 => 1.
  53. yetAnotherUsername:
  54. 192.23.50.40 => 2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement