Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Trainlands
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> train = new Dictionary<string, Dictionary<string, int>>();
- List<string> SplitedInput = new List<string>();
- string Trainname = null;
- string WagonName = null;
- int WagonPower = 0;
- string otherTrainName = null;
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "It's Training Men!")
- {
- break;
- }
- //ADDING NEW TRAIN WITH WAGONS
- if (input.Contains(" -> ") && input.Contains(" : "))
- {
- SplitedInput = input.Split(" ->:=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
- for (int i = 0; i < SplitedInput.Count; i++)
- {
- SplitedInput[i] = SplitedInput[i].Trim();
- }
- Trainname = SplitedInput[0];
- WagonName = SplitedInput[SplitedInput.Count - 2];
- WagonPower = int.Parse(SplitedInput[SplitedInput.Count - 1]);
- if (!train.ContainsKey(Trainname))
- {
- train.Add(Trainname, new Dictionary<string, int>());
- }
- if (!train[Trainname].ContainsKey(WagonName))
- {
- train[Trainname].Add(WagonName, 0);
- }
- train[Trainname][WagonName] = WagonPower;
- }
- //REVERSING THE WAGONS OF THE KNOWN TRAIN TO THE NEW TRAIN
- if (input.Contains(" -> ") && !input.Contains(" : "))
- {
- SplitedInput = input.Split(" ->:=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
- for (int i = 0; i < SplitedInput.Count; i++)
- {
- SplitedInput[i] = SplitedInput[i].Trim();
- }
- Trainname = SplitedInput[0];
- otherTrainName = SplitedInput[SplitedInput.Count - 1];
- if (Trainname == otherTrainName)
- {
- continue;
- }
- if (!train.ContainsKey(Trainname))
- {
- train.Add(Trainname, new Dictionary<string, int>());
- }
- foreach (var item in train[otherTrainName])
- {
- train[Trainname].Add(item.Key, item.Value);
- }
- train.Remove(otherTrainName);
- }
- // COPYING THE WAGONS OF THE OTHER TRAIN
- if (input.Contains(" = "))
- {
- SplitedInput = input.Split(" =-:>=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
- for (int i = 0; i < SplitedInput.Count; i++)
- {
- SplitedInput[i] = SplitedInput[i].Trim();
- }
- Trainname = SplitedInput[0];
- otherTrainName = SplitedInput[SplitedInput.Count - 1];
- if (Trainname == otherTrainName)
- {
- continue;
- }
- if (train.ContainsKey(Trainname))
- {
- train.Remove(Trainname); // <---- тук
- }
- train.Add(Trainname, new Dictionary<string, int>()); // и тук
- foreach (var item in train[otherTrainName])
- {
- train[Trainname].Add(item.Key, item.Value);
- }
- }
- }
- foreach (var item in train.OrderByDescending(X => X.Value.Values.Sum()).ThenBy(e => e.Key.Count()))
- {
- Console.WriteLine($"Train: {item.Key}");
- foreach (var wagon in item.Value.OrderByDescending(k => k.Value))
- {
- Console.WriteLine($"###{wagon.Key} - {wagon.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement