petyaminkova91

Untitled

Nov 28th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp4
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             Dictionary<string, int> resourses = new Dictionary<string, int>();
  14.  
  15.             while (input != "stop")
  16.             {
  17.                 string resourse = input;
  18.  
  19.                 int quantity = int.Parse(Console.ReadLine());
  20.  
  21.                 AddResourse(resourses, resourse, quantity);
  22.  
  23.                 input = Console.ReadLine();
  24.             }
  25.  
  26.             foreach (var kvp in resourses)
  27.             {
  28.                 Console.WriteLine($"{kvp.Key} -> {kvp.Value}");
  29.             }
  30.         }
  31.  
  32.         public static void AddResourse(Dictionary<string, int> resourses, string resourse, int quantity)
  33.         {
  34.             if (!resourses.ContainsKey(resourse))
  35.             {
  36.                 resourses.Add(resourse, 0);
  37.             }
  38.  
  39.             resourses[resourse] += quantity;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment