Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ExamPreparation
- {
- class Startup
- {
- static void Main()
- {
- int countSequences = int.Parse(Console.ReadLine());
- for (int i = 0; i < countSequences; i++)
- {
- int[] numbers = Console.ReadLine()
- .Trim()
- .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- List<int> found = new List<int>();
- for (int j = 0; j < numbers.Length; j++)
- {
- int currentNum = numbers[j];
- if (currentNum >= 0)
- {
- found.Add(currentNum);
- }
- else
- {
- if (j + 1 < numbers.Length)
- {
- currentNum += numbers[j + 1];
- }
- if (currentNum >= 0)
- {
- found.Add(currentNum);
- }
- j++;
- }
- }
- if (found.Any())
- {
- Console.WriteLine(string.Join(" ", found));
- }
- else
- {
- Console.WriteLine("(empty)");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement