Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

StoyanVitanov avatar StoyanVitanov 11 Точки

06. User Logs [Programming Fundamentals]

Много ще съм благодарен ако някой ми каже къде ми е грешката. Zero-тестовете минават, но другите не(27/100). :) 

http://pastebin.com/y2FUBUDm 

Това е условието:

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!

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

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.

Output

For every user found, you have to display each log in the format:

username:

IP => count, IP => count…

The IP addresses must be split with a comma, and each line of IP addresses must end with a dot.

Constraints

  • The number of commands will be in the range [1..50]
  • The IP addresses will be in the format of either IPv4 or IPv6.
  • The messages will be in the format: This&is&a&message
  • The username will be a string with length in the range [3..50]
  • Time limit: 0.3 sec. Memory limit: 16 MB. 

 

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.

Тагове:
0
Module: C# Advanced
NonaG avatar NonaG 111 Точки

IP=192.23.30.40 message='Hello&derps.' user=destroyer
IP=FE80:0000:0000:0000:0202:B3FF:FE1E:8329 message='Hey&son' user=mother
IP=FE80:0000:0000:0000:0202:B3FF:FE1E:8329 message='Hey&son' user=mother
IP=FE80:0000:0000:0000:0202:B3FF:FE1E:8329 message='Hey&son' user=destroyer

При този input речникът ти брои трето Value в полза на майката.

0
RadioDr avatar RadioDr 7 Точки

Защо трябва да се разделя по масив, след като броя на символите и в IP= и в user= са точно определен брой ?
Много по-просто е да се разделя по интервал и след това да се махат определен брой символи.
string[] comands = input.Split().ToArray();
                adress = comands[0].Remove(0, 3);
                user = comands[2].Remove(0, 5);

0
zhivko1985 avatar zhivko1985 34 Точки

Здравейте, тази задача толкова пъти я коригирах, че трябва да я напиша наново.

Проблемът е, че я докарах до 54%, а примерните тестове минават...

Някой (с права) можели да ми даде входа, на който ми гърми кода? Така ще мога да си намеря грешките и да пренапиша решението.

 

http://pastebin.com/9BSUQN6j

0
07/03/2017 18:07:13
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.