Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp4
- {
- class Program
- {
- static void Main(string[] args)
- {
- var fruit = Console.ReadLine();
- var dayOfWeek = Console.ReadLine();
- var calculation = double.Parse(Console.ReadLine());
- string[] workdaysDays = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
- string[] weekendDays = { "Saturday", "Sunday" };
- string[] realFuits = { "banana", "apple", "orange", "grapefruit", "kiwi", "pineapple", "grapes" };
- double[] workdaysPrice = { 2.50, 1.20, 0.85, 1.45, 2.70, 5.50, 3.85 };
- double[] weekendPrice = { 2.70, 1.25, 0.90, 1.60, 3.00, 5.60, 4.20 };
- Dictionary<string, double> workdays = new Dictionary<string, double>();
- for (int i = 0; i < realFuits.Length; i++) workdays.Add(realFuits[i], workdaysPrice[i]);
- Dictionary<string, double> weekend = new Dictionary<string, double>();
- for (int i = 0; i < realFuits.Length; i++) weekend.Add(realFuits[i], weekendPrice[i]);
- if (workdaysDays.Any(dayOfWeek.Contains)) TryParse(fruit, calculation, workdays);
- else if (weekendDays.Any(dayOfWeek.Contains)) TryParse(fruit, calculation, weekend);
- else Console.WriteLine("error");
- }
- private static void TryParse(string fruit, double calculation, Dictionary<string, double> workdays)
- {
- try
- {
- var price = workdays[fruit];
- Console.WriteLine($"{price * calculation:f2}");
- }
- catch (Exception)
- {
- Console.WriteLine("error");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement