TheBulgarianWolf

Kamino Factory/Biggest 1s subsequence

Oct 17th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using System.Numerics;
  6.  
  7. namespace SoftuniExercisesWithVariables
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Console.WriteLine("Enter the length of the sequences: ");
  15.             int length = int.Parse(Console.ReadLine());
  16.             string userInput = "";
  17.             int firstElement;
  18.             int biggestArraySub = 0;
  19.             string biggestSeq = "";
  20.             int currentSubsequence = 0;
  21.             int currentSubsequence2 = 0;
  22.             while((userInput = Console.ReadLine()) != "Clone them!")
  23.             {
  24.                 string[] userInputArray = userInput.Split("!");
  25.                 for(int i = 0; i < userInputArray.Length; i++)
  26.                 {
  27.                     if(userInputArray[i] == "1")
  28.                     {
  29.                        
  30.                         currentSubsequence += 1;
  31.                     }
  32.                     else
  33.                     {
  34.                         if(currentSubsequence > currentSubsequence2)
  35.                         {
  36.                             currentSubsequence2 = currentSubsequence;
  37.                         }
  38.                         currentSubsequence = 0;
  39.                     }
  40.                 }
  41.  
  42.                 if(currentSubsequence2 > biggestArraySub)
  43.                 {
  44.                     biggestSeq = userInput;
  45.                     biggestArraySub = currentSubsequence2;
  46.                 }
  47.                 currentSubsequence = 0;
  48.                 currentSubsequence2 = 0;
  49.  
  50.             }
  51.  
  52.             string[] biggestSequence = biggestSeq.Split("!");
  53.             for(int o = 0; o < biggestSequence.Length; o++)
  54.             {
  55.                 Console.Write(biggestSequence[o] + " ");
  56.             }
  57.            
  58.  
  59.         }
  60.     }
  61. }
  62.  
Add Comment
Please, Sign In to add comment