Advertisement
StoyanGrigorov

not my code

Oct 24th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. //12. Sum Adjacent Equal Numbers
  5. namespace SumAdjacentEqualNumbers
  6. {
  7.     class SumAdjacentEqualNumbers
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<double> list = Console.ReadLine().Split().Select(double.Parse).ToList();
  12.             bool canContinue = true;
  13.             while (canContinue)
  14.             {
  15.                 for (int i = 0; i <= list.Count - 2; i++)
  16.                 {
  17.                     if (i == list.Count - 1)
  18.                     {
  19.                         break;
  20.                     }
  21.  
  22.                     if (list[i] == list[i + 1])
  23.                     {
  24.                         list[i + 1] = list[i] * 2;
  25.                         //for (int j = i + 1; j < list.Count - 1; j++)
  26.                         //{
  27.                         //    list[j] = list[j + 1];
  28.                         //}
  29.                         //i = -1;
  30.                         list.Remove(list[i]);
  31.                     }
  32.                 }
  33.             }
  34.  
  35.  
  36.             Console.WriteLine(string.Join(" ", list));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement