Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 07. A Miner Task
- You will be given a sequence of strings, each on a new line. Every odd line on the console is representing a resource (e.g. Gold, Silver, Copper, and so on) and every even - quantity. Your task is to collect the resources and print them each on a new line.
- Print the resources and their quantities in the following format:
- {resource} –> {quantity}
- The quantities will be in the range [1 … 2 000 000 000]
- Examples
- Input Output Input Output
- Gold Gold -> 155 gold gold -> 170
- 155 Silver -> 10 155 silver -> 10
- Silver Copper -> 17 silver copper -> 17
- 10 10
- Copper copper
- 17 17
- stop gold
- 15
- stop
- using System;
- using System.Collections.Generic;
- namespace _07A_MinerTask
- {
- class Program
- {
- static void Main(string[] args)
- {
- var resourse = "";
- var minerTask = new Dictionary<string, int>();
- while (!(resourse = Console.ReadLine()).Equals("stop"))
- {
- var quantity = Console.ReadLine();
- var list = new List<string>();
- list.Add(resourse);
- list.Add(quantity);
- if (minerTask.ContainsKey(list[0]))
- {
- minerTask[list[0]] += int.Parse(list[1]);
- }
- else
- {
- minerTask.Add(list[0], int.Parse(list[1]));
- }
- }
- foreach (var item in minerTask)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment