Advertisement
nikolapetkov824

WinterVaporSale

Dec 24th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace RetakeFinalExamP01
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, double> mapPrice =
  13.                 new Dictionary<string, double>();
  14.  
  15.             Dictionary<string, string> mapDlc =
  16.                 new Dictionary<string, string>();
  17.  
  18.             string input = Console.ReadLine();
  19.  
  20.             string[] splitted = input.Split(", ");
  21.  
  22.             for (int i = 0; i < splitted.Length; i++)
  23.             {
  24.                 string tokens = splitted[i];
  25.  
  26.                 if (tokens.Contains("-"))
  27.                 {
  28.                     string[] gamesPrices = tokens.Split("-");
  29.                     string game = gamesPrices[0];
  30.                     double price = double.Parse(gamesPrices[1]);
  31.  
  32.                     if (mapPrice.ContainsKey(game)==false)
  33.                     {
  34.                         mapPrice.Add(game, price);
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     string[] gamesPrices = tokens.Split(":");
  40.                     string game = gamesPrices[0];
  41.                     string dlc = gamesPrices[1];
  42.  
  43.                     if (mapPrice.Keys.Any(d => d.Contains(game)))
  44.                     {
  45.                         mapDlc.Add(game, dlc);
  46.                     }
  47.  
  48.                     if (mapDlc.ContainsKey(game))
  49.                     {
  50.                         mapPrice[game] += 0.20 * mapPrice[game];
  51.                     }
  52.                 }
  53.             }
  54.  
  55.             foreach (var game in mapPrice
  56.                 .OrderBy(x=>x.Value))
  57.             {
  58.                 double price = 0.0;
  59.                 double loweredPrice = 0.0;
  60.  
  61.                 if (mapDlc.ContainsKey(game.Key) == false)
  62.                 {
  63.                      price = game.Value;
  64.                      loweredPrice = price - 0.20 * price;
  65.                 }
  66.                 else
  67.                 {
  68.                      price = game.Value;
  69.                      loweredPrice = price - 0.50 * price;
  70.                 }
  71.  
  72.                 foreach (var dlc in mapDlc)
  73.                 {
  74.                     if (game.Key == dlc.Key)
  75.                     {
  76.                         Console.WriteLine($"{dlc.Key} - {dlc.Value} - {loweredPrice:f2}");
  77.                     }
  78.                 }
  79.             }
  80.  
  81.             foreach (var game in mapPrice.OrderByDescending(x=>x.Value))
  82.             {
  83.                 double price = 0.0;
  84.                 double loweredPrice = 0.0;
  85.  
  86.                 if (mapDlc.ContainsKey(game.Key) == false)
  87.                 {
  88.                     price = game.Value;
  89.                     loweredPrice = price - 0.20 * price;
  90.                 }
  91.                 else
  92.                 {
  93.                     price = game.Value;
  94.                     loweredPrice = price - 0.50 * price;
  95.                 }
  96.  
  97.                 if (mapDlc.ContainsKey(game.Key) == false)
  98.                 {
  99.                     Console.WriteLine($"{game.Key} - {loweredPrice:f2}");
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement