Advertisement
nikolayneykov

Untitled

Mar 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Vapor
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, string> gameDLC = new Dictionary<string, string>();
  14.             Dictionary<string, decimal> game = new Dictionary<string, decimal>();
  15.             Dictionary<string, decimal> gameNoDLC = new Dictionary<string, decimal>();
  16.             List<string> input = Console.ReadLine().Split(", ").ToList();
  17.  
  18.             for (int i = 0; i < input.Count; i++)
  19.             {
  20.                 string cucrrentString = input[i];//.TrimStart();
  21.                 if (cucrrentString.Contains('-'))
  22.                 {
  23.                     string[] tokens = cucrrentString.Split('-');
  24.                     string nameOfgame = tokens[0];//.TrimStart();
  25.                     decimal price = decimal.Parse(tokens[1]);
  26.                     if (!game.ContainsKey(nameOfgame))
  27.                     {
  28.                         game[nameOfgame] = price;
  29.                     }
  30.                     else
  31.                     {
  32.                         game[nameOfgame] += price;
  33.                     }
  34.                 }
  35.                 else if (cucrrentString.Contains(':'))
  36.                 {
  37.                     string[] tokens = cucrrentString.Split(':');
  38.                     string nameOfgame = tokens[0];//.TrimStart();
  39.                     string nameOfDLC = tokens[1];
  40.                     if (game.ContainsKey(nameOfgame))
  41.                     {
  42.                         gameDLC[nameOfgame] = nameOfDLC;
  43.                         game[nameOfgame] *= 1.2m;
  44.                     }
  45.                 }
  46.             }
  47.             foreach (var item in gameDLC)
  48.             {
  49.                 var nameofGame = item.Key;
  50.                 if (game.ContainsKey(nameofGame))
  51.                 {
  52.                     game[nameofGame] *= 0.5m;
  53.                 }
  54.             }
  55.  
  56.             foreach (var item in game.OrderBy(x => x.Value))
  57.             {
  58.                 var gameDLCs = item.Key;
  59.                 var price = item.Value;
  60.                 if (gameDLC.ContainsKey(gameDLCs))
  61.                 {
  62.                     var currentDLC = gameDLC[gameDLCs];
  63.                     Console.WriteLine($"{gameDLCs} - {currentDLC} - {price:f2}");
  64.                 }
  65.             }
  66.             foreach (var gamem in game.OrderByDescending(x => x.Value))
  67.             {
  68.                 var gameDLCs = gamem.Key;
  69.                 var price = gamem.Value;
  70.                 if (!gameDLC.ContainsKey(gameDLCs))
  71.                 {
  72.                     Console.WriteLine("{0} - {1:f2}", gameDLCs, price * 0.8m);
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement