Advertisement
Aborigenius

Batteries

Jul 2nd, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 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 Batteries
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] capacities = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  14.             double[] usage = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  15.             List<double> result = new List<double>();
  16.             int testHours = int.Parse(Console.ReadLine());
  17.  
  18.             for (int i = 0; i < usage.Length; i++)
  19.             {
  20.                 if ((capacities[i] - (testHours * usage[i])) > 0)
  21.                 {
  22.                     result.Add(capacities[i] - (testHours * usage[i]));
  23.                 }
  24.                 else
  25.                 {
  26.                     result.Add(-Math.Ceiling((capacities[i]) / usage[i]));
  27.                 }
  28.             }
  29.  
  30.             for (int i = 0; i < result.Count; i++)
  31.             {
  32.                 if (result[i] > 0)
  33.                 {
  34.                     Console.WriteLine("Battery {0}: {1:f2} mAh ({2:f2})%", i + 1, result[i],
  35.                                                 (result[i] / capacities[i]) * 100);
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine("Battery {0}: dead (lasted {1} hours)", i+1, -result[i]);
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement