kirililchev3

Sum Adjacent Equal Numbers

Jun 9th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace P03Sum_Adjacent_Equal_Numbers
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] input = Console.ReadLine().Split(' ');
  11.             List<double> result = new List<double>();
  12.  
  13.             foreach (string num in input)
  14.             {
  15.                 result.Add(double.Parse(num));
  16.             }
  17.             for (int i = 0; i < result.Count - 1 ; i++)
  18.             {
  19.                 if (result[i] == result[i+1])
  20.                 {
  21.                     result[i + 1] = result[i] * 2;
  22.                     result.RemoveAt(i);
  23.                     i = -1;
  24.                 }
  25.             }
  26.             Console.WriteLine(string.Join(" ", result));
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment