06. Food Shortage
Как може да стане тази задача с Dictionary -> Ако може някакво решение
StartUp:
using System;
using System.Collections.Generic;
using System.Linq;
namespace _06._Food_Shortage
{
public class Program
{
static void Main(string[] args)
{
string command;
Dictionary<string, string> map = new Dictionary<string, string>();
int count = int.Parse(Console.ReadLine());
for (int i = 0; i < count; i++)
{
string[] names = Console.ReadLine().Split(" ");
if (names.Length == 4)
{
string name = names[0];
int age = int.Parse(names[1]);
string id = names[2];
string birthday = names[3];
ICitizens citizen = new Citizen(name, age, id, birthday);
map.Add(name, id);
}
else
{
string name = names[0];
int age = int.Parse(names[1]);
string group = names[2];
IRebel rebel = new Rebel(name, age, group);
map.Add(name, group);
}
}
int result = 0;
while ((command = Console.ReadLine()) != "End")
{
foreach(var names in map)
{
if(map.ContainsKey(command) && map.ContainsValue(names.Value))
{
result += 10;
}
else if(map.ContainsValue(names.Value))
{
result += 5;
}
else
{
}
}
}
Console.WriteLine(result);
}
}
}
This solution works for me. Thanks for sharing it. I appreciate it and uno online.