StoimenK

C# 2.2.Miner_Task

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