Advertisement
simonakancheva

Untitled

Apr 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TestFishes
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int limit = int.Parse(Console.ReadLine());
  10.             string name = string.Empty;
  11.             double weight = 0;
  12.             int counter = 0;
  13.             double sum = 0;
  14.             double fishPrice = 0;
  15.             int fishes = 0;
  16.  
  17.             for (int i = 1; i <= limit; i++)
  18.             {
  19.                 name = Console.ReadLine();              
  20.                 if (name == "Stop")
  21.                 {
  22.                     break;
  23.                 }
  24.                 fishes++;
  25.                 weight = double.Parse(Console.ReadLine());
  26.                 fishPrice = 0;
  27.  
  28.                 for (int j = 0; j < name.Length; j++)
  29.                 {
  30.                     char symbol = name[j];
  31.                     fishPrice += symbol;
  32.                     //Console.WriteLine("FP="+fishPrice);
  33.                    
  34.                 }
  35.  
  36.                 counter++;
  37.                 if (counter == 3)
  38.                 {
  39.                     sum += (fishPrice / weight);
  40.                     counter = 0;
  41.                 }
  42.                 else if (counter < 3)
  43.                 {
  44.                     sum -= (fishPrice / weight);
  45.                 }              
  46.             }
  47.            
  48.             if (name == "Stop")
  49.             {
  50.                 if (sum < 0)
  51.                 {
  52.                     Console.WriteLine($"Lyubo lost {Math.Abs(sum):f2} leva today.");
  53.                 }
  54.                 else
  55.                 {
  56.                     Console.WriteLine($"Lyubo's profit from {fishes} fishes is {sum:f2} leva.");
  57.                 }
  58.             }
  59.             else
  60.             {
  61.                 Console.WriteLine("Lyubo fulfilled the quota!");
  62.                 if (sum < 0)
  63.                 {
  64.                     Console.WriteLine($"Lyubo lost {Math.Abs(sum):f2} leva today.");
  65.                 }
  66.                 else
  67.                 {
  68.                     Console.WriteLine($"Lyubo's profit from {fishes} fishes is {sum:f2} leva.");
  69.                 }
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement