Advertisement
Guest User

Untitled

a guest
Oct 9th, 2016
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 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 A_Miner_Task
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Dictionary<string, decimal> mine = new Dictionary<string, decimal>();
  14. string userInput = Console.ReadLine();
  15.  
  16. //loops till "stop" is entered as a resource value
  17. while (userInput != "stop")
  18. {
  19. decimal amount = decimal.Parse(Console.ReadLine());
  20. //if resource exists
  21. if (mine.ContainsKey(userInput))
  22. {
  23. mine[userInput] += amount;
  24. }
  25. //if resource does not exists
  26. else
  27. {
  28. mine[userInput] = amount;
  29. }
  30.  
  31. //waits for the next loop
  32. userInput = Console.ReadLine();
  33. }
  34.  
  35. //prints the result ( if any)
  36. foreach (string key in mine.Keys)
  37. {
  38. Console.WriteLine($"{key} -> {mine[key]}");
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement