Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
1,553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 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 _03.A_Miner_Task
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Dictionary<string, int> myDict = new Dictionary<string, int>();
  14.  
  15.  
  16.  
  17.  
  18. for (int i = 1; ; i++)
  19. {
  20. string resource = Console.ReadLine();
  21.  
  22. if (resource.Equals("stop"))
  23. {
  24. break;
  25. }
  26.  
  27. int quantity = int.Parse(Console.ReadLine());
  28.  
  29. //Тук проверява дали съществува такъв key в myDic директроията и ако не го аддва
  30. if (!myDict.ContainsKey(resource))
  31. {
  32. myDict.Add(resource, 0);
  33. }
  34.  
  35. //тук увеличаваме quantity-то на key-a
  36. myDict[resource] += quantity;
  37. }
  38.  
  39. foreach (var item in myDict)
  40. {
  41. Console.WriteLine("{0} -> {1}", item.Key, item.Value);
  42. }
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement