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 ArraysAndLists
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> productsInStock = new Dictionary<string, int>();
- string[] input = Console.ReadLine().Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
- while(input[0] != "shopping")
- {
- string productName = input[1];
- int quantity = int.Parse(input[2]);
- if(!productsInStock.ContainsKey(productName))
- {
- productsInStock[productName] = 0;
- }
- productsInStock[productName]+=quantity;
- input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- }
- input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- while(input[0] != "exam")
- {
- string productName = input[1];
- int quantity = int.Parse(input[2]);
- if(!productsInStock.ContainsKey(productName))
- {
- Console.WriteLine($"{productName} doesn't exist");
- }
- else
- {
- if (productsInStock[productName] > 0)
- {
- productsInStock[productName] -= quantity;
- }
- else if (productsInStock[productName] <= 0)
- {
- productsInStock[productName] = 0;
- Console.WriteLine($"{productName} out of stock");
- }
- }
- input = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- }
- foreach (KeyValuePair<string,int> item in productsInStock)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement