Advertisement
YavorGrancharov

Batteries

Jul 2nd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Batteries
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             double[] capacities = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  12.  
  13.             double[] usage = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  14.  
  15.             int hours = int.Parse(Console.ReadLine());
  16.  
  17.             int count = 0;
  18.             double lasted = 0.0;
  19.             double status = 0.0;
  20.             double capacitiesLeft = 0.0;
  21.             for (int i = 0; i < capacities.Length; i++)
  22.             {
  23.                 for (int j = 0; j < usage.Length; j++)
  24.                 {
  25.                     status = ((capacities[i] - (hours * usage[i])) / capacities[i]) * 100;
  26.                     capacitiesLeft = capacities[i] - (hours * usage[i]);
  27.                     lasted = Math.Ceiling(capacities[i] / usage[i]);
  28.                 }
  29.                 count++;
  30.                 if (status > 0)
  31.                 {
  32.                     Console.WriteLine($"Battery {count}: {capacitiesLeft:F2} mAh ({status:F2})%");
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.WriteLine($"Battery {count}: dead (lasted {lasted} hours)");
  37.                 }
  38.             }          
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement