Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, int> resourses = new Dictionary<string, int>();
- while (input != "stop")
- {
- string resourse = input;
- int quantity = int.Parse(Console.ReadLine());
- AddResourse(resourses, resourse, quantity);
- input = Console.ReadLine();
- }
- foreach (var kvp in resourses)
- {
- Console.WriteLine($"{kvp.Key} -> {kvp.Value}");
- }
- }
- public static void AddResourse(Dictionary<string, int> resourses, string resourse, int quantity)
- {
- if (!resourses.ContainsKey(resourse))
- {
- resourses.Add(resourse, 0);
- }
- resourses[resourse] += quantity;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment