Здравей pace13,
В горния десен ъгъл има една лупа нарисувана, цъкни я и цъкни да търси само във форумите, после напиши Legendary Farming и ще ти излезнат 2 дузини решение и можеш да си избираш кое ти харесва най-много :). Задачата беше решена на упражненията и можеш да погледнеш видеото за речници, ако много се затрудняваш :).
Сръбско Unleashed: https://pastebin.com/LR1TzHQ1.
Благодаря много!
Здравей, изпращам ти и моето решение. Дано да съм помогнал.https://pastebin.com/uRWitEDk
Благодаря много!
using System;
using System.Collections.Generic;
using System.Linq;
namespace LegendaryFarming
{
class LegendaryFarming
{
static void Main(string[] args)
{
SortedDictionary<string, int> keyItems = new SortedDictionary<string, int> { { "shards", 0 }, { "fragments", 0 }, { "motes", 0 } };
SortedDictionary<string, int> junkItems = new SortedDictionary<string, int>();
bool hasLegendary = false;
while (hasLegendary == false)
{
string loot = Console.ReadLine().ToLower();
SortItems(loot, keyItems, junkItems);
if (keyItems.Values.Max() >= 250)
{
hasLegendary = true;
break;
}
}
Results(keyItems, junkItems);
}
private static void Results(SortedDictionary<string, int> keyItems, SortedDictionary<string, int> junkItems)
{
string legendary = keyItems.Aggregate((comparison, current) => comparison.Value > current.Value ? comparison : current).Key;
switch (legendary)
{
case "shards":
Console.WriteLine("Shadowmourne obtained!");
keyItems[legendary] -= 250;
PrintRest(keyItems, junkItems);
break;
case "fragments":
Console.WriteLine("Valanyr obtained!");
keyItems[legendary] -= 250;
PrintRest(keyItems, junkItems);
break;
case "motes":
Console.WriteLine("Dragonwrath obtained!");
keyItems[legendary] -= 250;
PrintRest(keyItems, junkItems);
break;
}
}
private static void PrintRest(SortedDictionary<string, int> keyItems, SortedDictionary<string, int> junkItems)
{
foreach (KeyValuePair<string, int> leftOverKeyitems in keyItems.OrderByDescending(x => x.Value))
{
Console.WriteLine($"{leftOverKeyitems.Key}: {leftOverKeyitems.Value}");
}
foreach (KeyValuePair<string, int> leftOverJunkItems in junkItems)
{
Console.WriteLine($"{leftOverJunkItems.Key}: {leftOverJunkItems.Value}");
}
}
private static void SortItems(string loot, SortedDictionary<string, int> keyItems, SortedDictionary<string, int> junkItems)
{
List<string> farmedItems = loot.Split().ToList();
for (int i = 0; i < farmedItems.Count; i += 2)
{
int itemQuantity = int.Parse(farmedItems[i]);
string item = farmedItems[i + 1];
if (item == "shards" || item == "fragments" || item == "motes")
{
AddToKeyItems(keyItems, item, itemQuantity);
}
else
{
AddToJunkItems(junkItems, item, itemQuantity);
}
if (keyItems.Values.Max() >= 250)
{
break;
}
}
}
private static void AddToJunkItems(SortedDictionary<string, int> junkItems, string item, int itemQuantity)
{
if (junkItems.ContainsKey(item))
{
junkItems[item] += itemQuantity;
}
else
{
junkItems.Add(item, itemQuantity);
}
}
private static void AddToKeyItems(SortedDictionary<string, int> keyItems, string item, int itemQuantity)
{
if (keyItems.ContainsKey(item))
{
keyItems[item] += itemQuantity;
}
else
{
keyItems.Add(item, itemQuantity);
}
}
}
}
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
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}");
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program
{
public static void Main()
{
#if DEBUG
Console.SetIn(new StreamReader("../../input.txt"));
#endif
var dragonDictionary = new Dictionary<string, SortedSet<Dragon>>();
int dragonCount = int.Parse(Console.ReadLine());
for (int counter = 0; counter < dragonCount; counter++)
{
Dragon dragon = ReadDragon();
UpdateDragonDictionary(dragonDictionary, dragon);
}
foreach (var pair in dragonDictionary)
{
Console.WriteLine("{0}::({1:F2}/{2:F2}/{3:F2})",
pair.Key,
pair.Value
.Select(dragon => dragon.Damage)
.Average(),
pair.Value
.Select(dragon => dragon.Health)
.Average(),
pair.Value
.Select(dragon => dragon.Armor)
.Average());
Console.WriteLine(string.Join("\n", pair.Value));
}
}
private static void UpdateDragonDictionary(Dictionary<string, SortedSet<Dragon>> dragonDictionary, Dragon dragon)
{
if (!dragonDictionary.ContainsKey(dragon.Type))
{
dragonDictionary[dragon.Type] =
new SortedSet<Dragon>(DragonComparer.GetComparer());
}
if (dragonDictionary[dragon.Type].Contains(dragon))
dragonDictionary[dragon.Type].Remove(dragon);
dragonDictionary[dragon.Type].Add(dragon);
}
private static Dragon ReadDragon()
{
string[] dragonArgs = Console.ReadLine().Split();
string type = dragonArgs[0];
string name = dragonArgs[1];
int? damage = (dragonArgs[2] != "null")
? (int?)int.Parse(dragonArgs[2])
: null;
int? health = (dragonArgs[3] != "null")
? (int?)int.Parse(dragonArgs[3])
: null;
int? armor = (dragonArgs[4] != "null")
? (int?)int.Parse(dragonArgs[4])
: null;
return new Dragon(type, name, damage, health, armor);
}
}
class Dragon
{
private const int DefaultDamage = 45;
private const int DefaultHealth = 250;
private const int DefaultArmor = 10;
public string Name { get; private set; }
public string Type { get; private set; }
public int Damage { get; private set; }
public int Health { get; private set; }
public int Armor { get; private set; }
public Dragon(string type, string name, int? damage, int? health, int? armor)
{
Name = name;
Type = type;
Damage = damage ?? DefaultDamage;
Health = health ?? DefaultHealth;
Armor = armor ?? DefaultArmor;
}
// override object.Equals
public override bool Equals(object obj)
{
if (obj is Dragon && obj != null)
{
Dragon dragon = (Dragon)obj;
return (dragon.Name == this.Name && dragon.Type == this.Type);
}
return false;
}
// override object.GetHashCode
public override int GetHashCode()
{
return (Name + Type).GetHashCode();
}
// override object.ToString
public override string ToString()
{
return string.Format("-{0} -> damage: {1}, health: {2}, armor: {3}",
Name,
Damage,
Health,
Armor);
}
}
class DragonComparer : IComparer<Dragon>
{
public int Compare(Dragon x, Dragon y)
{
return string.Compare(x.Name, y.Name);
}
public static IComparer<Dragon> GetComparer()
{
return new DragonComparer();
}
}
Ето и от мен едно решение
мерси