Guest User

Untitled

a guest
Mar 8th, 2025
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.  
  7.         List<decimal> input = Console.ReadLine()
  8.             .Split()
  9.             .Select(decimal.Parse)
  10.             .ToList();
  11.  
  12.         for (int i = 0; i < input.Count-1; i++)
  13.         {
  14.             if (input[i] == input[i+1])
  15.             {
  16.                 input[i] += input[i + 1];
  17.                 input.RemoveAt(i+1);
  18.                 i = -1;
  19.             }
  20.         }
  21.  
  22.         Console.WriteLine(string.Join(" ", input));
  23.  
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment