Advertisement
nikolayneykov

Untitled

Mar 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         Dictionary<string, string[]> games = new Dictionary<string, string[]>();
  10.         string[] input = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries);
  11.  
  12.         foreach (var item in input)
  13.         {
  14.             if (item.Contains("-"))
  15.             {
  16.                 string[] tokens = item.Split('-');
  17.                 string game = tokens[0];
  18.                 string price = tokens[1];
  19.                 games[game] = new string[2];
  20.                 games[game][0] = price;
  21.             }
  22.             else if (item.Contains(":"))
  23.             {
  24.                 string[] tokens = item.Split(':');
  25.                 string game = tokens[0];
  26.                 string dlc = tokens[1];
  27.  
  28.                 if (games.ContainsKey(game))
  29.                 {
  30.                     games[game][1] = dlc;
  31.                     games[game][0] = (decimal.Parse(games[game][0]) * 1.2m).ToString();
  32.                 }
  33.             }
  34.         }
  35.  
  36.  
  37.         foreach (var item in games.OrderBy(x => decimal.Parse(x.Value[0])))
  38.         {
  39.             if (item.Value[1] != null)
  40.             {
  41.                 Console.WriteLine($"{item.Key} - {item.Value[1]} - {decimal.Parse(item.Value[0]) * 0.5m:F2}");
  42.             }
  43.         }
  44.  
  45.         foreach (var item in games.OrderByDescending(x => decimal.Parse(x.Value[0])))
  46.         {
  47.             if (item.Value[1] == null)
  48.             {
  49.                 Console.WriteLine($"{item.Key} - {decimal.Parse(item.Value[0]) * 0.8m:F2}");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement