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 Exam_shopping
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> dict = new Dictionary<string, int>();
- string stock = Console.ReadLine();
- while (stock != "shopping time")
- {
- string[] stockAdd = stock.Split(' ').ToArray();
- string stockItem = stockAdd[1];
- int stockItemQuantity = int.Parse(stockAdd[2]);
- if (!dict.ContainsKey(stockItem))
- {
- dict[stockItem] = stockItemQuantity;
- }
- else
- {
- dict[stockItem] += stockItemQuantity;
- }
- stock = Console.ReadLine();
- }
- string buy = Console.ReadLine();
- while (buy != "exam time")
- {
- string[] buying = buy.Split(' ').ToArray();
- string buyItem = buying[1];
- int buyItemQuantity = int.Parse(buying[2]);
- if (!dict.ContainsKey(buyItem))
- {
- Console.WriteLine($"{buyItem} doesn't exist");
- }
- else
- {
- if (dict[buyItem] == 0)
- {
- Console.WriteLine($"{buyItem} out of stock");
- }
- else if (buyItemQuantity >= dict[buyItem])
- {
- dict[buyItem] = 0;
- }
- else
- {
- dict[buyItem] -= buyItemQuantity;
- }
- }
- buy = Console.ReadLine();
- }
- foreach (KeyValuePair<string, int> item in dict)
- {
- if (item.Value > 0)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement