-
Notifications
You must be signed in to change notification settings - Fork 0
/
SrybskoUnleashed.cs
133 lines (113 loc) · 4.15 KB
/
SrybskoUnleashed.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
namespace _10.SrybskoUnleashed
{
using System;
using System.Collections.Generic;
using System.Linq;
public class SrybskoUnleashed
{
public static void Main()
{
var venues = new Dictionary<string, Dictionary<string, int>>();
string line = Console.ReadLine();
while (line != "End")
{
string[] input = line.Split(' ');
// Check if input consists of 4 parts
if (input.Length < 4)
{
line = Console.ReadLine();
continue;
}
// Check if there's an input part, starting with @. Loop doesn't start from 0, as if input[0]
bool atFound = false; // starts with an @, then it's obviously wrong
int venueStart = 0;
for (int i = 1; i < input.Length; i++)
{
if (input[i].StartsWith("@"))
{
atFound = true;
venueStart = i;
break;
}
}
if (!atFound)
{
line = Console.ReadLine();
continue;
}
// Build artist name
string artist = string.Empty;
for (int i = 0; i < venueStart; i++)
{
artist += input[i];
artist += " ";
}
artist = artist.TrimEnd();
// Check if artist's name is of up to 3 words
if ((artist.Split(' ')).Length > 3)
{
line = Console.ReadLine();
continue;
}
// Build venue name
string venueName = string.Empty;
for (int i = venueStart; i < input.Length - 2; i++)
{
venueName += input[i];
venueName += " ";
}
venueName = venueName.TrimEnd();
// Check if venue's name is of up to 3 words
if ((venueName.Split(' ')).Length > 3)
{
line = Console.ReadLine();
continue;
}
// Check if there's another @
bool anotherAt = false;
for (int i = 1; i < venueName.Length; i++)
{
if (venueName[i].Equals(new char[] { '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }))
{
anotherAt = true;
break;
}
}
if (anotherAt)
{
line = Console.ReadLine();
continue;
}
venueName = venueName.TrimStart('@');
int ticketPrice = 0;
bool priceExists = int.TryParse(input[input.Length - 2], out ticketPrice);
int ticketCount = 0;
bool countExists = int.TryParse(input[input.Length - 1], out ticketCount);
if (!priceExists || !countExists)
{
line = Console.ReadLine();
continue;
}
if (!venues.ContainsKey(venueName))
{
venues[venueName] = new Dictionary<string, int>();
}
if (!venues[venueName].ContainsKey(artist))
{
venues[venueName][artist] = 0;
}
venues[venueName][artist] += ticketPrice * ticketCount;
line = Console.ReadLine();
}
foreach (var outerKvp in venues)
{
Console.WriteLine(outerKvp.Key);
var artistsAtVenue = outerKvp.Value;
foreach (var innerKvp in artistsAtVenue.OrderByDescending(x => x.Value))
{
Console.WriteLine($"# {innerKvp.Key} -> {innerKvp.Value}");
}
}
}
}
}