Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _08.Fishing
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int quota = int.Parse(Console.ReadLine());
  14.             decimal profit = 0;
  15.             for (int i = 1; i <= quota; i++)
  16.             {
  17.                 string fishName = Console.ReadLine();
  18.                 if (fishName=="Stop")
  19.                 {
  20.                     if (profit >= 0)
  21.                     {
  22.                         Console.WriteLine($"Lyubo's profit from {i-1} fishes is {profit:f2} leva.");
  23.                     }
  24.                     else
  25.                     {
  26.                         Console.WriteLine($"Lyubo lost {Math.Abs(profit):f2} leva today.");
  27.                     }
  28.                     return;
  29.                 }
  30.                 decimal fishWeight = decimal.Parse(Console.ReadLine());
  31.                 decimal price = 0;
  32.                 int asciSum = 0;
  33.                 for (int j = 0; j < fishName.Length; j++)
  34.                 {
  35.                     char asciChar = char.Parse(fishName[j].ToString());
  36.                     int asci = asciChar;
  37.                     asciSum += asci;
  38.                 }
  39.                 price = asciSum / fishWeight;
  40.                 if (i % 3 == 0)
  41.                 {
  42.                     profit += price;
  43.                 }
  44.                 else
  45.                 {
  46.                     profit -= price;
  47.                 }
  48.             }
  49.             Console.WriteLine("Lyubo fulfilled the quota!");
  50.             if (profit >= 0)
  51.             {
  52.                 Console.WriteLine($"Lyubo's profit from {quota} fishes is {profit:f2} leva.");
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine($"Lyubo lost {profit:f2} leva today.");
  57.             }
  58.             Console.WriteLine();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement