petyaminkova91

Untitled

Nov 28th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01_VaporWinterSale
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, double> gamesWithPrices = new Dictionary<string, double>();
  12.             Dictionary<string, string> gamesWithDLC = new Dictionary<string, string>();
  13.  
  14.             string[] gamesData = Console.ReadLine().Split(", ");
  15.  
  16.             for (int i = 0; i < gamesData.Length; i++)
  17.             {
  18.                 string current = gamesData[i];
  19.                 string gameName = String.Empty;
  20.                 if (current.Contains("-"))
  21.                 {
  22.                     string[] currentGameAndPrice = current.Split("-");
  23.                     gameName = currentGameAndPrice[0];
  24.                     double price = double.Parse(currentGameAndPrice[1]);
  25.  
  26.                     AddToDictionaryGamesWithPrices(gamesWithPrices, gameName, price);
  27.                 }
  28.                 else
  29.                 {
  30.                     string[] currentGameWithDLC = current.Split(":");
  31.                     gameName = currentGameWithDLC[0];
  32.                     string currentDLC = currentGameWithDLC[1];
  33.  
  34.                     AddToDictionaryGamesWithDLC(gamesWithPrices, gameName, gamesWithDLC, currentDLC);
  35.                 }
  36.             }
  37.             ChangeGamesPrices(gamesWithDLC, gamesWithPrices);
  38.             PrintGamesWithDLC(gamesWithDLC, gamesWithPrices);
  39.             gamesWithPrices = PrintGamesWithoutDLC(gamesWithPrices, gamesWithDLC);
  40.         }
  41.  
  42.         private static void AddToDictionaryGamesWithDLC(Dictionary<string, double> gamesWithPrices, string gameName, Dictionary<string, string> gamesWithDLC,
  43.             string currentDLC)
  44.         {
  45.             if (gamesWithPrices.ContainsKey(gameName))
  46.             {
  47.                 gamesWithDLC.Add(gameName, currentDLC);
  48.                 gamesWithPrices[gameName] *= 1.2;
  49.             }
  50.         }
  51.  
  52.         private static void AddToDictionaryGamesWithPrices(Dictionary<string, double> gamesWithPrices, string gameName, double price)
  53.         {
  54.             if (!gamesWithPrices.ContainsKey(gameName))
  55.             {
  56.                 gamesWithPrices.Add(gameName, 0);
  57.             }
  58.             gamesWithPrices[gameName] = price;
  59.         }
  60.  
  61.         private static Dictionary<string, double> PrintGamesWithoutDLC(Dictionary<string, double> gamesWithPrices, Dictionary<string, string> gamesWithDLC)
  62.         {
  63.             foreach (var kvp in gamesWithPrices.OrderByDescending(x => x.Value))
  64.             {
  65.                 string currentGame = kvp.Key;
  66.                 double price = kvp.Value;
  67.                 price *= 0.8;
  68.  
  69.                 Console.WriteLine($"{currentGame} - {price:f2}");
  70.             }
  71.             return gamesWithPrices;
  72.         }
  73.  
  74.         private static void PrintGamesWithDLC(Dictionary<string, string> gamesWithDLC, Dictionary<string, double> gamesWithPrices)
  75.         {
  76.             foreach (var kvp in gamesWithPrices.OrderBy(x => x.Value))
  77.             {
  78.                 string game = kvp.Key;
  79.  
  80.                 foreach (var kvpGame in gamesWithDLC)
  81.                 {
  82.                     if (kvpGame.Key == game)
  83.                     {
  84.                         Console.WriteLine($"{game} - {kvpGame.Value} - {gamesWithPrices[game]:f2}");
  85.                         gamesWithPrices.Remove(game);
  86.                         break;
  87.                     }
  88.                 }
  89.             }
  90.         }
  91.  
  92.         private static void ChangeGamesPrices(Dictionary<string, string> gamesWithDLC, Dictionary<string, double> gamesWithPrices)
  93.         {
  94.             foreach (var game in gamesWithDLC)
  95.             {
  96.                 string currentGame = game.Key;
  97.  
  98.                 if (gamesWithPrices.ContainsKey(currentGame))
  99.                 {
  100.                     gamesWithPrices[currentGame] *= 0.5;
  101.                 }
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment