paskal06

Untitled

Jun 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 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.            
  14.             double[] Capacity = Console
  15.                             .ReadLine()
  16.                             .Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  17.                             .Select(item => double.Parse(item))
  18.                             .ToArray();
  19.             double[] HundredPercent = Capacity;
  20.             double[] UPH = Console
  21.                             .ReadLine()
  22.                             .Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  23.                             .Select(item => double.Parse(item))
  24.                             .ToArray();
  25.  
  26.             int hours = int.Parse(Console.ReadLine());
  27.             double hrs = hours;
  28.             int[] lasted = new int[Capacity.Length];
  29.             double[] percentage = new double[Capacity.Length];
  30.  
  31.            
  32.             while (hours > 0)
  33.             {
  34.                 for (int i = 0; i < Capacity.Length; i++)
  35.                 {
  36.                    
  37.                     Capacity[i] -= UPH[i];
  38.                     if (Capacity[i] < 0)
  39.                     {
  40.                        
  41.                         continue;
  42.                     }
  43.                     lasted[i]++;
  44.  
  45.                 }
  46.                 hours--;
  47.             }
  48.            
  49.             for (int i = 0; i < Capacity.Length; i++)
  50.             {
  51.                 if (Capacity[i] < 0) { Console.WriteLine("Battery {0}: dead (lasted {1} hours)",i+1,lasted[i]+1); } else {
  52.                     percentage[i] = (Capacity[i]/HundredPercent[i])*100;
  53.                     Console.WriteLine("Battery {1}: {0:0.00} mAh ({2:0.00})%", Capacity[i], i+1, percentage[i]); }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment