Advertisement
silvana1303

hello france

Jun 17th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] list = Console.ReadLine().Split('|').ToArray();
  14.  
  15.             double budget = double.Parse(Console.ReadLine());
  16.  
  17.             List<double> bought = new List<double>();
  18.  
  19.             for (int i = 0; i < list.Length; i++)
  20.             {
  21.                 string[] cutList = list[i].Split("->").ToArray();
  22.  
  23.                 if (cutList[0] == "Clothes")
  24.                 {
  25.                     budget = Clothes(budget, bought, cutList);
  26.                 }
  27.                 if (cutList[0] == "Shoes")
  28.                 {
  29.                     budget = Shoes(budget, bought, cutList);
  30.                 }
  31.                 if (cutList[0] == "Accessories")
  32.                 {
  33.                     budget = Accessories(budget, bought, cutList);
  34.                 }
  35.             }
  36.             double profitSum, profit;
  37.             ProfitOperations(bought, out profitSum, out profit);
  38.  
  39.             Output(budget, bought, profitSum, profit);
  40.  
  41.         }
  42.  
  43.         private static void Output(double budget, List<double> bought, double profitSum, double profit)
  44.         {
  45.             for (int i = 0; i < bought.Count; i++)
  46.             {
  47.                 Console.Write($"{bought[i]:F2} ");
  48.             }
  49.             Console.WriteLine();
  50.             Console.WriteLine($"Profit: {profit:F2}");
  51.  
  52.             if (profitSum + budget >= 150)
  53.             {
  54.                 Console.WriteLine("Hello, France!");
  55.             }
  56.             else
  57.             {
  58.                 Console.WriteLine("Time to go.");
  59.             }
  60.         }
  61.  
  62.         private static void ProfitOperations(List<double> bought, out double profitSum, out double profit)
  63.         {
  64.             double boughtSum = bought.Sum();
  65.  
  66.             for (int i = 0; i < bought.Count; i++)
  67.             {
  68.                 bought[i] *= 1.40;
  69.             }
  70.  
  71.             profitSum = bought.Sum();
  72.             profit = profitSum - boughtSum;
  73.         }
  74.  
  75.         private static double Accessories(double budget, List<double> bought, string[] cutList)
  76.         {
  77.             double price = double.Parse(cutList[1]);
  78.             if (price <= 20.50 && price <= budget)
  79.             {
  80.                 budget -= price;
  81.                 bought.Add(price);
  82.             }
  83.  
  84.             return budget;
  85.         }
  86.  
  87.         private static double Shoes(double budget, List<double> bought, string[] cutList)
  88.         {
  89.             double price = double.Parse(cutList[1]);
  90.             if (price <= 35.00 && price <= budget)
  91.             {
  92.                 budget -= price;
  93.                 bought.Add(price);
  94.             }
  95.  
  96.             return budget;
  97.         }
  98.  
  99.         private static double Clothes(double budget, List<double> bought, string[] cutList)
  100.         {
  101.             double price = double.Parse(cutList[1]);
  102.             if (price <= 50.00 && price <= budget)
  103.             {
  104.                 budget -= price;
  105.                 bought.Add(price);
  106.             }
  107.  
  108.             return budget;
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement