TheBulgarianWolf

A Miner's Task

Feb 22nd, 2021
1,526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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.             string input;
  11.             Dictionary<string, int> dataBase = new Dictionary<string, int>();
  12.             while((input = Console.ReadLine()) != "stop")
  13.             {
  14.                 string material = input;
  15.                 string quant = Console.ReadLine();
  16.                 if(quant == "stop")
  17.                 {
  18.                     break;
  19.                 }
  20.                 int quantity = int.Parse(quant);
  21.                 if (dataBase.ContainsKey(material))
  22.                 {
  23.                     dataBase[material] += quantity;
  24.                 }
  25.                 else
  26.                 {
  27.                     dataBase.Add(material, quantity);
  28.                 }
  29.             }
  30.  
  31.             foreach (var materi in dataBase)
  32.             {
  33.                 Console.WriteLine(materi.Key + " -> " + materi.Value);
  34.             }
  35.         }
  36.     }
  37. }
  38.  
Add Comment
Please, Sign In to add comment