Advertisement
obedmarsh

06. Batteries

Jul 2nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 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 LearnToProgramCSharp
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] capacity = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  14.             double[] usageForHour = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  15.             int amountHours = int.Parse(Console.ReadLine());
  16.             double longevity = 0.00;
  17.             for (int i = 0; i < capacity.Length; i++)
  18.             {
  19.                 if ((capacity[i] / usageForHour[i]) < amountHours)
  20.                 {
  21.                     Console.WriteLine("Battery {0}: dead (lasted {1} hours)", i + 1, Math.Ceiling(capacity[i] / usageForHour[i]));
  22.                 }
  23.                 else if ((capacity[i] / usageForHour[i]) > amountHours)
  24.                 {
  25.                     longevity = capacity[i] - (usageForHour[i] * amountHours);
  26.                     Console.WriteLine("Battery {0}: {1:F2} mAh ({2:F2})%", i + 1, longevity, (longevity * 100 / capacity[i]));
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement