Advertisement
radidim

P02 (C# Shell App Paste)

Jul 21st, 2020
1,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.             var dict = new Dictionary<string, int>();
  15.             var count = -1;
  16.             var resource = string.Empty;
  17.             var quantity = 0;
  18.             while(true)
  19.            {
  20.             var input = Console.ReadLine();
  21.             count++;
  22.             if(input == "stop")
  23.             {
  24.                 break;
  25.             }
  26.            
  27.             if(count%2==0)
  28.             {
  29.                 resource = input;
  30.                 if(!dict.ContainsKey(resource))
  31.             {
  32.                 dict[resource] = new int();
  33.             }
  34.             }
  35.             else
  36.             {
  37.                 quantity = int.Parse(input);
  38.                 dict[resource]+=quantity;
  39.             }
  40.            
  41.            
  42.         }
  43.            foreach(var kvp in dict)
  44.            {
  45.             Console.WriteLine($"{kvp.Key} -> {kvp.Value}");
  46.            }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement