Advertisement
radidim

09.1Kamino_Factory (C# Shell App Paste)

Jan 4th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.70 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 length = 0;
  18.             int sum = 0;
  19.             int startIndex = 0;
  20.             int row = 0;
  21.             int currentRow = 1;
  22.             bool isFound = false;
  23.            
  24.             int[] DNA = new int[dnaLength];
  25.            
  26.             while(true)
  27.             {
  28.                 string line = Console.ReadLine();
  29.                
  30.                 if(line == "clone")
  31.                
  32.                 {
  33.                     break;
  34.                 }
  35.                
  36.                 int[] currentDNA = line
  37.                 .Split('!')
  38.                 .Select(int.Parse)
  39.                 .ToArray();
  40.                
  41.                 int currentStartIndex = -1;
  42.                 int currentLength = 0;
  43.                 int currentSum = 0;
  44.                 for(int i=0;i<currentDNA.Length;i++)
  45.                 {
  46.                     if(currentDNA[i]==1)
  47.                     {
  48.                         currentSum++;
  49.                        
  50.                     }
  51.                    
  52.                 }
  53.                
  54.                 for(int i=0; i<currentDNA.Length; i++)
  55.                 {
  56.                     if(currentDNA[i] == 1)
  57.                     {
  58.                        
  59.                         if(!isFound)
  60.                         {
  61.                             currentStartIndex = i;
  62.                         }
  63.                        
  64.                         currentLength++;
  65.                        
  66.                         if(currentLength>length)
  67.                         {
  68.                             length = currentLength;
  69.                             startIndex = currentStartIndex;
  70.                             sum = currentSum;
  71.                             row = currentRow;
  72.                             DNA = currentDNA;
  73.                         }
  74.                        
  75.                         else if(currentLength==length)
  76.                         {
  77.                             if(currentStartIndex<startIndex)
  78.                             {
  79.                                 length = currentLength;
  80.                                 startIndex = currentStartIndex;
  81.                                 sum = currentSum;
  82.                                 row = currentRow;
  83.                                 DNA = currentDNA;
  84.                             }
  85.                             else if(currentSum>sum)
  86.                             {
  87.                                 length = currentLength;
  88.                                 startIndex = currentStartIndex;
  89.                                 sum = currentSum;
  90.                                 row = currentRow;
  91.                                 DNA = currentDNA;
  92.                             }
  93.                         }
  94.                     }
  95.                     else
  96.                     {
  97.                         isFound = false;
  98.                         currentStartIndex = -1;
  99.                         //currentSum = 0;
  100.                         currentLength = 0;
  101.                         //currentRow = 1;
  102.                     }
  103.                    
  104.                 }
  105.                 currentRow++;
  106.                
  107.                
  108.                
  109.             }
  110.            
  111.             Console.WriteLine($"row {row} sum {sum}.");
  112.             Console.WriteLine(string.Join(" ", DNA));
  113.            
  114.            
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement