Advertisement
EvstatiZarkov

Problem 5 – Pillars test 1 fail

Apr 13th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. class Pillars
  4. {
  5.     static void Main()
  6.     {
  7.         byte[] input = new byte[8];
  8.         byte[] sumArrey = new byte[8];
  9.        
  10.  
  11.  
  12.  
  13.  
  14.         for (int i = 0; i < input.Length; i++)
  15.         {
  16.             input[i] = byte.Parse(Console.ReadLine());
  17.  
  18.             for (int n = 0; n < input.Length; n++)
  19.             {
  20.  
  21.  
  22.                 int mask = 1 << n;
  23.                 int m = input[i] & mask;
  24.                 if (m != 0)
  25.                 {
  26.                     sumArrey[n]++;
  27.                 }
  28.  
  29.             }
  30.         }
  31.        
  32.         Array.Reverse(sumArrey);
  33.  
  34.         int sum = 0;
  35.  
  36.  
  37.         for (int i = 0; i < sumArrey.Length; i++)
  38.         {
  39.             sum += sumArrey[i];
  40.  
  41.         }
  42.         int sumleft = 0;
  43.         int position = 0;
  44.  
  45.         for (int i = 0; i < sumArrey.Length; i++)
  46.         {
  47.  
  48.             int sumright = sum - sumleft - sumArrey[i];
  49.  
  50.             if (sumright == sumleft)
  51.             {
  52.                 position = i;
  53.                 break;
  54.             };
  55.             sumleft += sumArrey[i];
  56.         }
  57.         if (position == 0)
  58.         {
  59.             Console.WriteLine("No");
  60.         }
  61.         else
  62.         {
  63.             Console.WriteLine(7-position);
  64.             Console.WriteLine(sumleft);
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement