Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03.A_Miner_Task
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> myDict = new Dictionary<string, int>();
- for (int i = 1; ; i++)
- {
- string resource = Console.ReadLine();
- if (resource.Equals("stop"))
- {
- break;
- }
- int quantity = int.Parse(Console.ReadLine());
- //Тук проверява дали съществува такъв key в myDic директроията и ако не го аддва
- if (!myDict.ContainsKey(resource))
- {
- myDict.Add(resource, 0);
- }
- //тук увеличаваме quantity-то на key-a
- myDict[resource] += quantity;
- }
- foreach (var item in myDict)
- {
- Console.WriteLine("{0} -> {1}", item.Key, item.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement