YavorGrancharov

Raindrops

Jan 4th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Raindrops
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int regionsAmount = int.Parse(Console.ReadLine());
  10.             decimal density = decimal.Parse(Console.ReadLine());
  11.  
  12.             decimal sum = 0;
  13.             decimal regionCoefficient = 0;
  14.             for (int i = 0; i < regionsAmount; i++)
  15.             {
  16.                 string line = Console.ReadLine();
  17.                 string[] tokens = line.Split(' ');
  18.                 decimal raindropsCount = decimal.Parse(tokens[0]);
  19.                 decimal squareMeters = decimal.Parse(tokens[1]);
  20.  
  21.                 sum += raindropsCount / squareMeters;
  22.                 regionCoefficient = sum / density;
  23.             }
  24.             if (density <= 0)
  25.             {
  26.                 Console.WriteLine(sum);
  27.             }
  28.             else
  29.             {
  30.                 Console.WriteLine("{0:F3}", regionCoefficient);
  31.             }
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment