Advertisement
Dilyana86

Untitled

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