Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace A_Miner_Task
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, int> resourcesAndQuantities = new Dictionary<string, int>();
  12.  
  13.             while (true)
  14.             {
  15.                 string resources = Console.ReadLine();
  16.                 if (resources == "stop")
  17.                 {
  18.                     break;
  19.                 }
  20.                 int quantity = int.Parse(Console.ReadLine());
  21.                 if (!resourcesAndQuantities.ContainsKey(resources))
  22.                 {
  23.                     resourcesAndQuantities.Add(resources, 0);
  24.  
  25.                 }
  26.                 resourcesAndQuantities[resources] += quantity;
  27.             }
  28.  
  29.             foreach (var type in resourcesAndQuantities)
  30.             {
  31.                 Console.WriteLine($"{type.Key} -> {type.Value}");
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement