Advertisement
bacco

A Miner Task

Jun 8th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace AMinerTask
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             var mine = new Dictionary<string, int>();
  13.  
  14.             string  commands = Console.ReadLine();
  15.  
  16.             string metal = "";
  17.             int quantity = 0;
  18.  
  19.             while (commands != "stop")
  20.             {
  21.                 metal = commands;
  22.                 quantity = int.Parse(Console.ReadLine());
  23.  
  24.                 if (!mine.ContainsKey(metal))
  25.                 {
  26.                     mine.Add(metal, quantity);
  27.                 }
  28.                 else
  29.                 {
  30.                     mine[metal] += quantity;
  31.                 }
  32.                 commands = Console.ReadLine();
  33.             }
  34.             foreach (var pair in mine)
  35.             {
  36.                 Console.WriteLine($"{pair.Key} -> {pair.Value}");
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement