Problem 09 ForceBook - Associative Arrays - Exercise
Здравейте,
При задача 09 ForceBook https://judge.softuni.bg/Contests/Compete/Index/1213#8 с решение https://pastebin.com/3NsMHzp5, Judge ми дава 90/100. Моля за помощ!
Здравейте,
При задача 09 ForceBook https://judge.softuni.bg/Contests/Compete/Index/1213#8 с решение https://pastebin.com/3NsMHzp5, Judge ми дава 90/100. Моля за помощ!
Здравей. Коригирах кода ти, тествах и работи на 100/100. Няма да описвам всички грешки, просто погледни какво съм премахнал и 1-2 неща добавил.
using System;
using System.Collections.Generic;
using System.Linq;
namespace _09_Exe_ForceBook
{
class Program
{
static void Main(string[] args)
{
Dictionary<string,string> forceUsers = new Dictionary<string, string>();
string command = null;
while ((command = Console.ReadLine()) != "Lumpawaroo")
{
var test = command.Split();
if (test.Contains("|"))
{
string[] commandArr = command.Split(" | ");
string forceSide = commandArr[0];
string forceUser = commandArr[1];
if (!forceUsers.ContainsKey(forceUser))
forceUsers.Add(forceUser, forceSide);
}
else if(test.Contains("->"))
{
string[] commandArr = command.Split(" -> ");
string forceUser = commandArr[0];
string forceSide = commandArr[1];
if (forceUsers.ContainsKey(forceUser))
forceUsers[forceUser] = forceSide;
else
forceUsers.Add(forceUser,forceSide);
Console.WriteLine($"{forceUser} joins the {forceSide} side!");
}
}
foreach (var users in forceUsers
.GroupBy(x => x.Value)
.OrderByDescending(x => x.Count())
.ThenBy(c => c.Key))
{
Console.WriteLine($"Side: {users.Key}, Members: {users.Count()}");
foreach (var elm in users.OrderBy(t => t.Key))
{
Console.WriteLine($"! {elm.Key}");
}
}
}
}
}
Благодаря много!