Моля за съдействие, задача User log
Условия:
You are given an input in the format:
IP=(IP.Address) message=(A&sample&message) user=(username)
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:
username:
IP => count, IP => count.
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:
destroyer:
192.23.30.40 => 1.
The username destroyer has sent a message from ip 192.23.30.40 once.
Check the examples below. They will further clarify the assignment.
Input |
Output |
IP=192.23.30.40 message='Hello&derps.' user=destroyer IP=192.23.30.41 message='Hello&yall.' user=destroyer IP=192.23.30.40 message='Hello&hi.' user=destroyer IP=192.23.30.42 message='Hello&Dudes.' user=destroyer end |
destroyer: 192.23.30.40 => 2, 192.23.30.41 => 1, 192.23.30.42 => 1. |
IP=FE80:0000:0000:0000:0202:B3FF:FE1E:8329 message='Hey&son' user=mother IP=192.23.33.40 message='Hi&mom!' user=child0 IP=192.23.30.40 message='Hi&from&me&too' user=child1 IP=192.23.30.42 message='spam' user=destroyer IP=192.23.30.42 message='spam' user=destroyer IP=192.23.50.40 message='' user=yetAnotherUsername IP=192.23.50.40 message='comment' user=yetAnotherUsername IP=192.23.155.40 message='Hello.' user=unknown end |
child0: 192.23.33.40 => 1. child1: 192.23.30.40 => 1. destroyer: 192.23.30.42 => 2. mother: FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1. unknown: 192.23.155.40 => 1. yetAnotherUsername: 192.23.50.40 => 2. |
Решение: https://pastebin.com/P7rXVJ5M
Моят резултат на втория тест е следният:
child0:
FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1,
192.23.33.40 => 1,
192.23.30.40 => 1,
192.23.30.42 => 2,
192.23.50.40 => 2,
192.23.155.40 => 1.
child1:
FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1,
192.23.33.40 => 1,
192.23.30.40 => 1,
192.23.30.42 => 2,
192.23.50.40 => 2,
192.23.155.40 => 1.
destroyer:
FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1,
192.23.33.40 => 1,
192.23.30.40 => 1,
192.23.30.42 => 2,
192.23.50.40 => 2,
192.23.155.40 => 1.
mother:
FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1,
192.23.33.40 => 1,
192.23.30.40 => 1,
192.23.30.42 => 2,
192.23.50.40 => 2,
192.23.155.40 => 1.
unknown:
FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1,
192.23.33.40 => 1,
192.23.30.40 => 1,
192.23.30.42 => 2,
192.23.50.40 => 2,
192.23.155.40 => 1.
yetAnotherUsername:
FE80:0000:0000:0000:0202:B3FF:FE1E:8329 => 1,
192.23.33.40 => 1,
192.23.30.40 => 1,
192.23.30.42 => 2,
192.23.50.40 => 2,
192.23.155.40 => 1.
Супер! Много Благодаря! :)