Advertisement
elena1234

AMinerTask

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