MiroslavKisov

BePositive

Oct 6th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _17.BePositive
  5. {
  6.     class StartUp
  7.     {
  8.         static void Main()
  9.         {
  10.             int countSequences = int.Parse(Console.ReadLine());
  11.  
  12.             for (int i = 0; i < countSequences; i++)
  13.             {
  14.                 string[] input = Console.ReadLine().Split(' ');
  15.                 var numbers = new List<int>();
  16.  
  17.                 for (int j = 0; j < input.Length; j++)
  18.                 {
  19.                     if (!input[j].Equals(string.Empty))
  20.                     {
  21.                         int num = int.Parse(input[j]);
  22.                         numbers.Add(num);
  23.                     }
  24.                 }
  25.  
  26.                 bool found = false;
  27.                 for (int j = 0; j < numbers.Count; j++)
  28.                 {
  29.                     int currentNum = numbers[j];
  30.  
  31.                     if (currentNum >= 0)
  32.                     {
  33.                         Console.Write(currentNum + " ");
  34.  
  35.                         found = true;
  36.                     }
  37.                     else if(j + 1 < numbers.Count)
  38.                     {
  39.                         currentNum += numbers[j + 1];
  40.                         j += 1;
  41.                         if (currentNum >= 0)
  42.                         {
  43.  
  44.                             Console.Write(currentNum + " ");
  45.  
  46.                             found = true;
  47.                         }
  48.                     }
  49.                 }            
  50.                 if (!found)
  51.                 {
  52.                     Console.WriteLine("(empty)");
  53.                 }
  54.                 else
  55.                 {
  56.                     Console.WriteLine();
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment