Advertisement
PlamenMI81

17 zada4a

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