SvetlanPetrova

Fishing SoftUni

Mar 31st, 2019 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Fishing
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int quota = int.Parse(Console.ReadLine());
  10.             string fishName = Console.ReadLine();
  11.             int fishCount = 0;
  12.             double profit = 0;
  13.  
  14.             while (fishName != "Stop")
  15.             {
  16.                 double fishKg = double.Parse(Console.ReadLine());
  17.                 fishCount++;
  18.  
  19.                 double price = 0;
  20.  
  21.                 for (int i = 0; i < fishName.Length; i++)
  22.                 {
  23.                     price = fishName[i] / fishKg;
  24.                     if (fishCount % 3 == 0)
  25.                     {
  26.                         profit += price;
  27.                     }
  28.                     else
  29.                     {
  30.                         profit -= price;
  31.                     }
  32.                 }
  33.  
  34.                 if (fishCount == quota)
  35.                 {
  36.                     Console.WriteLine("Lyubo fulfilled the quota!");
  37.                     break;
  38.                 }
  39.  
  40.                 fishName = Console.ReadLine();
  41.             }
  42.  
  43.             if (profit >= 0)
  44.             {
  45.                 Console.WriteLine($"Lyubo's profit from {fishCount} fishes is {profit:f2} leva.");
  46.             }
  47.             else
  48.             {
  49.                 Console.WriteLine($"Lyubo lost {Math.Abs(profit):f2} leva today.");
  50.             }
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment