Teo_Yanchev

Dictionaries - 02. AMinerTask - C# Fundamentals

Oct 4th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _02._AMinerTask
  5. {
  6. class AMinerTask
  7. {
  8. static void Main()
  9. {
  10. Dictionary<string, int> cart = new Dictionary<string, int>();
  11.  
  12.  
  13.  
  14. while (true)
  15. {
  16. string resource = Console.ReadLine();
  17. if (resource == "stop")
  18. {
  19. break;
  20. }
  21. int quantity = int.Parse(Console.ReadLine());
  22.  
  23. if (!cart.ContainsKey(resource))
  24. {
  25. cart[resource] = 0;
  26. }
  27.  
  28. cart[resource] += quantity;
  29. }
  30.  
  31. foreach (var resource in cart)
  32. {
  33. Console.WriteLine($"{resource.Key} -> {resource.Value}");
  34. }
  35. }
  36. }
  37. }
  38.  
Add Comment
Please, Sign In to add comment