LusienGG

[C#] Be Positive

May 19th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. namespace BePositive
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class BePositiveMain
  7.     {
  8.         public 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().Trim().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.  
  28.                 for (int j = 0; j < numbers.Count; j++)
  29.                 {
  30.                     int currentNum = numbers[j];
  31.  
  32.                     if (currentNum >= 0)
  33.                     {
  34.                         if (found)
  35.                         {
  36.                             Console.Write(" ");
  37.                         }
  38.  
  39.                         Console.Write(currentNum);
  40.  
  41.                         found = true;
  42.                     }
  43.                     else
  44.                     {
  45.                         int count = numbers.Count - 1;
  46.                         if (j != count)
  47.                         {
  48.                             currentNum += numbers[j + 1];
  49.                         }
  50.                         j++;
  51.                         if (currentNum >= 0)
  52.                         {
  53.                             if (found)
  54.                             {
  55.                                 Console.Write(" ");
  56.                             }
  57.  
  58.                             Console.Write(currentNum);
  59.                            
  60.                             found = true;
  61.                         }
  62.                     }
  63.                 }
  64.  
  65.                 if (!found)
  66.                 {
  67.                     Console.Write("(empty)");
  68.                 }
  69.                 Console.WriteLine();
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment