Advertisement
radidim

main(kamino) (C# Shell App Paste)

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