Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01_VaporWinterSale
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, double> gamesWithPrices = new Dictionary<string, double>();
- Dictionary<string, string> gamesWithDLC = new Dictionary<string, string>();
- string[] gamesData = Console.ReadLine().Split(", ");
- for (int i = 0; i < gamesData.Length; i++)
- {
- string current = gamesData[i];
- string gameName = String.Empty;
- if (current.Contains("-"))
- {
- string[] currentGameAndPrice = current.Split("-");
- gameName = currentGameAndPrice[0];
- double price = double.Parse(currentGameAndPrice[1]);
- AddToDictionaryGamesWithPrices(gamesWithPrices, gameName, price);
- }
- else
- {
- string[] currentGameWithDLC = current.Split(":");
- gameName = currentGameWithDLC[0];
- string currentDLC = currentGameWithDLC[1];
- AddToDictionaryGamesWithDLC(gamesWithPrices, gameName, gamesWithDLC, currentDLC);
- }
- }
- ChangeGamesPrices(gamesWithDLC, gamesWithPrices);
- PrintGamesWithDLC(gamesWithDLC, gamesWithPrices);
- gamesWithPrices = PrintGamesWithoutDLC(gamesWithPrices, gamesWithDLC);
- }
- private static void AddToDictionaryGamesWithDLC(Dictionary<string, double> gamesWithPrices, string gameName, Dictionary<string, string> gamesWithDLC,
- string currentDLC)
- {
- if (gamesWithPrices.ContainsKey(gameName))
- {
- gamesWithDLC.Add(gameName, currentDLC);
- gamesWithPrices[gameName] *= 1.2;
- }
- }
- private static void AddToDictionaryGamesWithPrices(Dictionary<string, double> gamesWithPrices, string gameName, double price)
- {
- if (!gamesWithPrices.ContainsKey(gameName))
- {
- gamesWithPrices.Add(gameName, 0);
- }
- gamesWithPrices[gameName] = price;
- }
- private static Dictionary<string, double> PrintGamesWithoutDLC(Dictionary<string, double> gamesWithPrices, Dictionary<string, string> gamesWithDLC)
- {
- foreach (var kvp in gamesWithPrices.OrderByDescending(x => x.Value))
- {
- string currentGame = kvp.Key;
- double price = kvp.Value;
- price *= 0.8;
- Console.WriteLine($"{currentGame} - {price:f2}");
- }
- return gamesWithPrices;
- }
- private static void PrintGamesWithDLC(Dictionary<string, string> gamesWithDLC, Dictionary<string, double> gamesWithPrices)
- {
- foreach (var kvp in gamesWithPrices.OrderBy(x => x.Value))
- {
- string game = kvp.Key;
- foreach (var kvpGame in gamesWithDLC)
- {
- if (kvpGame.Key == game)
- {
- Console.WriteLine($"{game} - {kvpGame.Value} - {gamesWithPrices[game]:f2}");
- gamesWithPrices.Remove(game);
- break;
- }
- }
- }
- }
- private static void ChangeGamesPrices(Dictionary<string, string> gamesWithDLC, Dictionary<string, double> gamesWithPrices)
- {
- foreach (var game in gamesWithDLC)
- {
- string currentGame = game.Key;
- if (gamesWithPrices.ContainsKey(currentGame))
- {
- gamesWithPrices[currentGame] *= 0.5;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment