Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Numerics;
- namespace TestGround
- {
- class Test
- {
- public static void Main()
- {
- int countSequences = int.Parse(Console.ReadLine());
- for (int i = 0; i < countSequences; i++)
- {
- int[] input = Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- List<int> data = new List<int>();
- for (int j = 0; j < input.Length - 1; j++)
- {
- int currentNum = input[j];
- if (currentNum >= 0)
- {
- data.Add(currentNum);
- }
- else
- {
- currentNum += input[j + 1];
- if (currentNum >= 0)
- {
- data.Add(currentNum);
- }
- j++;
- }
- }
- if (input.Length > 2)
- {
- if (( input[input.Length - 2] >= 0 && input[input.Length - 1] >= 0) || (input[input.Length - 3] < 0 && input[input.Length - 1] >= 0))
- {
- data.Add(input[input.Length - 1]);
- }
- }
- else if (input.Length == 2)
- {
- if (input[input.Length - 2] >= 0 && input[input.Length - 1] >= 0)
- {
- data.Add(input[input.Length - 1]);
- }
- }
- else
- {
- if (input[0] >= 0)
- {
- data.Add(input[0]);
- }
- }
- if (data.Count > 0)
- {
- Console.WriteLine(string.Join(" ", data));
- }
- else
- {
- Console.WriteLine("(empty)");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement