Advertisement
bullit3189

Sum Adjacent Equal Nums

Jan 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. List<double> numbers = Console.ReadLine().Split().Select(double.Parse).ToList();
  10.  
  11. for (int i=0; i<numbers.Count-1; i++)
  12. {
  13. double currNum = numbers[i];
  14. double nextNum = numbers[i+1];
  15.  
  16. if (currNum == nextNum)
  17. {
  18. numbers[i]*=2;
  19. numbers.Remove(nextNum);
  20. i=-1;
  21. }
  22. }
  23. Console.WriteLine(string.Join(" ",numbers));
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement