Advertisement
diyanborisov

SetsAndDictionaries/AMinerTask

Jun 13th, 2016
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace AMinerTask
  8. {
  9.     class AMinerTask
  10.     {
  11.         static void Main()
  12.         {
  13.             Dictionary<string, int> resourceChart = new Dictionary<string, int>();
  14.             int inputValue;
  15.             string inputMetal = Console.ReadLine()
  16.                 .Trim();
  17.            
  18.  
  19.             while (inputMetal != "stop")
  20.             {
  21.                 inputValue = int.Parse(Console.ReadLine()
  22.                     .Trim());
  23.                 if (inputValue >= 0)
  24.                 {
  25.                     if (resourceChart.ContainsKey(inputMetal))
  26.                     {
  27.                         resourceChart[inputMetal] += inputValue;
  28.                     }
  29.                     else
  30.                     {
  31.                         resourceChart.Add(inputMetal, inputValue);
  32.                     }
  33.                 }
  34.                 inputMetal = Console.ReadLine();
  35.             }
  36.  
  37.             foreach (var item in resourceChart)
  38.             {
  39.                 Console.WriteLine("{0} -> {1}", item.Key, item.Value);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement