-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex01_concert.cs
103 lines (98 loc) · 3.78 KB
/
ex01_concert.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace ex01_concert
{
class BandMembers
{
public string Members { get; set; }
public int Time { get; set; }
public BandMembers()
{
this.Members = "";
this.Time = 0;
}
}
class Program
{
static void Main()
{
int totalTime = 0;
string command = "";
Dictionary<string, BandMembers> concertBands = new Dictionary<string, BandMembers>();
string lasBand = "";
string finalInputBand = "";
while((command = Console.ReadLine()) != "start of concert")
{
string currentBandInsert = "";
List<string> entry = command.Split(new [] { "; ", ", " },
StringSplitOptions.RemoveEmptyEntries).ToList();
if (entry.Count >= 2)
{
for (int i = 2; i < entry.Count; i++)
{
currentBandInsert += entry[i] + ",";
}
}
if (entry[0] == "Add")
{
if(!concertBands.Keys.Contains(entry[1]))
{
concertBands.Add(entry[1], new BandMembers { Members = currentBandInsert });
}
else if(concertBands.Keys.Contains(entry[1]))
{
List<string> tempNames = currentBandInsert.Split(',').ToList();
List<string> tempExistingNames = concertBands[entry[1]].Members.Split(',').ToList();
foreach (var item in tempNames)//
{
if(!tempExistingNames.Contains(item))
{
concertBands[entry[1]].Members += item + ",";
tempExistingNames.Add(item);
}
}
}
}
else if (entry[0] == "Play")
{
if (!concertBands.Keys.Contains(entry[1]))
{
concertBands.Add(entry[1], new BandMembers { Time = int.Parse(entry[2]) });
totalTime += int.Parse(entry[2]);
}
else if (concertBands.Keys.Contains(entry[1]))
{
if (concertBands[entry[1]].Time == 0)//
{
concertBands[entry[1]].Time = int.Parse(entry[2]);
totalTime += int.Parse(entry[2]);
}
else if (concertBands[entry[1]].Time > 0)
{
concertBands[entry[1]].Time += int.Parse(entry[2]);
totalTime += int.Parse(entry[2]);
}
}
}
lasBand = entry[1];
}
finalInputBand = Console.ReadLine();
//Print result
Console.WriteLine("Total time: " + totalTime);
var ordered = concertBands.OrderByDescending(x => x.Value.Time).ThenBy(x => x.Key);
foreach (var band in ordered)
{
Console.WriteLine($"{band.Key} -> {band.Value.Time}");
}
//
Console.WriteLine(finalInputBand);
string[] ouputMembers = concertBands[finalInputBand].Members.Split(',', StringSplitOptions.RemoveEmptyEntries);
foreach (var item in ouputMembers)
{
Console.WriteLine($"=> {item}");
}
}
}
}