Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _10
- {
- class Program
- {
- static void Main(string[] args)
- {
- int times = int.Parse(Console.ReadLine());
- List<User> AllUsers = new List<User>();
- bool alreadyExistsUser = false;
- for (int i = 0; i < times; i++)
- {
- string[] input = Console.ReadLine().Split(' ');
- string inputIp = input[0];
- string inputName = input[1];
- int inputDuration = int.Parse(input[2]);
- foreach (var user in AllUsers)
- {
- if (user.Name == inputName)
- {
- alreadyExistsUser = true;
- user.duration += inputDuration;
- if (!user.Ips.Contains(inputIp))
- {
- user.Ips.Add(inputIp);
- break;
- }
- else
- {
- break;
- }
- }
- }
- if (!alreadyExistsUser)
- {
- AllUsers.Add(new User(inputName, inputIp, inputDuration));
- }
- }
- AllUsers = AllUsers.OrderBy(a => a.Name).ToList();
- foreach (var user in AllUsers)
- {
- user.Ips.Sort();
- Console.Write($"{user.Name}: {user.duration} [");
- string outIp = "";
- foreach (var ip in user.Ips)
- {
- outIp += $"{ip}, ";
- }
- outIp = outIp.Remove(outIp.Length - 2);
- outIp += "]";
- Console.WriteLine(outIp);
- }
- }
- class User
- {
- public string Name;
- public int duration = 0;
- public List<string> Ips = new List<string>();
- public User (string Name , string FirstIp , int FirstDuration)
- {
- this.Name = Name;
- Ips.Add(FirstIp);
- duration += FirstDuration;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement