Advertisement
YavorGrancharov

A_Miner_Task(dict)

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