petyaminkova91

Untitled

Nov 28th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 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.             Dictionary<string, int> resourses = new Dictionary<string, int>();
  13.  
  14.             while (input != "stop")
  15.             {
  16.                 string resourse = input;
  17.                 int quantity = int.Parse(Console.ReadLine());
  18.                 AddResourse(resourses, resourse, quantity);
  19.                 input = Console.ReadLine();
  20.             }
  21.             foreach (var kvp in resourses)
  22.             {
  23.                 Console.WriteLine($"{kvp.Key} -> {kvp.Value}");
  24.             }
  25.         }
  26.         public static void AddResourse(Dictionary<string, int> resourses, string resourse, int quantity)
  27.         {
  28.             if (!resourses.ContainsKey(resourse))
  29.             {
  30.                 resourses.Add(resourse, 0);
  31.             }
  32.             resourses[resourse] += quantity;
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment