Advertisement
tanya_zheleva

Untitled

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