Advertisement
fbinnzhivko

Be Positive

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