Created
August 1, 2015 16:53
-
-
Save vdonchev/0f0b753c5ceebe74e604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
class VladkosNotebook | |
{ | |
static void Main() | |
{ | |
var dataRecovered = new Dictionary<string, Dictionary<string, List<string>>>(); | |
while (true) | |
{ | |
string[] playerSheet = Console.ReadLine() | |
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); | |
if (playerSheet[0] == "END") break; | |
string sheetColor = playerSheet[0]; | |
string reccordType = playerSheet[1]; | |
string thirdParameter = playerSheet[2]; | |
if (!dataRecovered.ContainsKey(sheetColor)) | |
{ | |
dataRecovered.Add(sheetColor, new Dictionary<string, List<string>>()); | |
} | |
if (!dataRecovered[sheetColor].ContainsKey(reccordType)) | |
{ | |
dataRecovered[sheetColor].Add(reccordType, new List<string>()); | |
} | |
if (reccordType == "win" || reccordType == "loss") | |
{ | |
dataRecovered[sheetColor][reccordType].Add(reccordType); | |
if (!dataRecovered[sheetColor].ContainsKey("opponents")) | |
{ | |
dataRecovered[sheetColor].Add("opponents", new List<string>() { thirdParameter }); | |
} | |
else | |
{ | |
dataRecovered[sheetColor]["opponents"].Add(thirdParameter); | |
} | |
} | |
else if (reccordType == "age" || reccordType == "name") | |
{ | |
dataRecovered[sheetColor][reccordType].Add(thirdParameter); | |
} | |
} | |
var orderedData = dataRecovered | |
.OrderBy(a => a.Key) | |
.Where(prop => prop.Value.ContainsKey("age") && prop.Value.ContainsKey("name")); | |
if (!orderedData.Any()) | |
{ | |
Console.WriteLine("No data recovered."); | |
return; | |
} | |
foreach (var colorSheet in orderedData) | |
{ | |
Console.WriteLine("Color: {0}", colorSheet.Key); | |
Console.WriteLine("-age: {0}", colorSheet.Value["age"][0]); | |
Console.WriteLine("-name: {0}", colorSheet.Value["name"][0]); | |
if (colorSheet.Value.ContainsKey("opponents")) | |
{ | |
Console.WriteLine("-opponents: {0}", | |
string.Join(", ", colorSheet.Value["opponents"] | |
.OrderBy(a => a[0]))); | |
} | |
else | |
{ | |
Console.WriteLine("-opponents: (empty)"); | |
} | |
var rank = CalculateOpponentRank(colorSheet); | |
Console.WriteLine("-rank: {0:F2}", rank); | |
} | |
} | |
static double CalculateOpponentRank(KeyValuePair<string, Dictionary<string, List<string>>> colorSheet) | |
{ | |
int wins = (colorSheet.Value.ContainsKey("win")) | |
? colorSheet.Value["win"].Count() | |
: 0; | |
int losses = (colorSheet.Value.ContainsKey("loss")) | |
? colorSheet.Value["loss"].Count() | |
: 0; | |
double rank = (wins + 1) / (double) (losses + 1); | |
return rank; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment