Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- //12. Sum Adjacent Equal Numbers
- namespace SumAdjacentEqualNumbers
- {
- class SumAdjacentEqualNumbers
- {
- static void Main(string[] args)
- {
- List<double> list = Console.ReadLine().Split().Select(double.Parse).ToList();
- bool canContinue = true;
- while (canContinue)
- {
- for (int i = 0; i <= list.Count - 2; i++)
- {
- if (i == list.Count - 1)
- {
- break;
- }
- if (list[i] == list[i + 1])
- {
- list[i + 1] = list[i] * 2;
- //for (int j = i + 1; j < list.Count - 1; j++)
- //{
- // list[j] = list[j + 1];
- //}
- //i = -1;
- list.Remove(list[i]);
- }
- }
- }
- Console.WriteLine(string.Join(" ", list));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement