Advertisement
radidim

09.Kamino Factory (C# Shell App Paste)

Jan 3rd, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.48 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is //in no way responsible for the code posted by any user.
  2. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is //in no way responsible for the code posted by any user.
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7.  
  8. namespace CSharp_Shell
  9. {
  10.  
  11.     public static class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.             int dnaLength = int.Parse(Console.ReadLine());
  16.            
  17.             int sum =0;
  18.             int length  = 0;
  19.             int row = 0;
  20.             int currentRow=1;
  21.             int startIndex=-1;
  22.            
  23.             int[] DNA = new int[dnaLength];
  24.            
  25.            
  26.             while(true)
  27.             {
  28.                 string input = Console.ReadLine();
  29.                
  30.                 if(input == "clone")
  31.                 {
  32.                     break;
  33.                 }
  34.                
  35.                 int[] currentDNA = input
  36.                 .Split('!')
  37.                 .Select(int.Parse)
  38.                 .ToArray();
  39.                
  40.                 int currentSum = 0;
  41.                
  42.                 for(int i = 0;i<currentDNA.Length;i++)
  43.                 {
  44.                     if(currentDNA[i]==1)
  45.                     {
  46.                         currentSum++;
  47.                     }
  48.                 }
  49.                
  50.                 int currentLength=0;
  51.                 int currentStartIndex=-1;
  52.                 bool isTrue = false;
  53.                
  54.                 for(int i=0;i<dnaLength;i++)
  55.                
  56.                 {
  57.                     if(currentDNA[i]==1)
  58.                     {
  59.                         if(!isTrue)
  60.                         {
  61.                             currentStartIndex=i;
  62.                         }
  63.                        
  64.                         currentLength++;
  65.                        
  66.                         if (currentLength>length)
  67.                     {
  68.                         length = currentLength;
  69.                         startIndex=currentStartIndex;
  70.                         row=currentRow;
  71.                         sum=currentSum;
  72.                        
  73.                         DNA = currentDNA;
  74.                     }
  75.                    
  76.                     else if (currentLength==length)
  77.                     {
  78.                         if(currentStartIndex<startIndex)
  79.                         {
  80.                            length = currentLength;
  81.                            startIndex = currentStartIndex;
  82.                            row=currentRow;
  83.                            sum=currentSum;
  84.                            
  85.                            DNA = currentDNA;
  86.                         }
  87.                        
  88.                         else if(currentSum>sum)
  89.                         {
  90.                             length = currentLength;
  91.                             row=currentRow;
  92.                             sum=currentSum;
  93.                        
  94.                             DNA = currentDNA;
  95.                         }
  96.                     }
  97.                     else
  98.                     {
  99.                         currentStartIndex = -1;
  100.                         currentRow = 1;
  101.                         isTrue=false;
  102.                     }
  103.                        
  104.                     }
  105.                    
  106.                 }
  107.                 currentRow++;
  108.                
  109.             }
  110.            
  111.             Console.WriteLine($"Best DNA sample {row} with sum: {sum}.");
  112.  
  113.             Console.WriteLine(string.Join(" ", DNA));
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement