kirililchev3

Debug Be Positive

Jun 3rd, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. namespace BePositive_Debuging
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class BePositive_broken
  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().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  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.                         if (!(j == numbers.Count - 1))
  46.                         {
  47.                             currentNum += numbers[j + 1];
  48.                             numbers.RemoveAt(j + 1);
  49.                             if (currentNum >= 0)
  50.                             {
  51.                                 if (found)
  52.                                 {
  53.                                     Console.Write(" ");
  54.                                 }
  55.  
  56.                                 Console.Write(currentNum);
  57.  
  58.                                 found = true;
  59.                             }
  60.                         }
  61.                     }
  62.                 }
  63.  
  64.                 if (!found)
  65.                 {
  66.                     Console.Write("(empty)");
  67.                 }
  68.  
  69.                 Console.WriteLine();
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment