archangelmihail

Pillars

Dec 4th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Pillars
  8. {
  9.     class Pillars
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //initialization
  14.             int[,] grid = new int[8, 8];
  15.             bool zero = true;
  16.             for (int row = 0; row < 8; row++)
  17.             {
  18.                 int number = int.Parse(Console.ReadLine());
  19.                 string numberToString = Convert.ToString(number, 2).PadLeft(8, '0');
  20.                 for (int col = 0; col < 8; col++)
  21.                 {
  22.                     grid[row, col] = int.Parse(numberToString[col].ToString());
  23.                     if (grid[row, col] == 1)
  24.                     {
  25.                         zero = false;
  26.                     }
  27.                 }
  28.             }
  29.  
  30.             //for (int i = 0; i < 8; i++)
  31.             //{
  32.             //    for (int j = 0; j < 8; j++)
  33.             //    {
  34.             //        Console.Write(grid[i,j]);
  35.             //    }
  36.             //    Console.WriteLine();
  37.             //}
  38.             // declare variables
  39.  
  40.             int result = 0;
  41.             bool win = false;
  42.             byte pil = 0;
  43.  
  44.             if (zero)
  45.             {
  46.                 Console.WriteLine("7");
  47.                 Console.WriteLine("0");
  48.                 return;
  49.             }
  50.             //solution
  51.             while (pil < 8)
  52.             {
  53.                 int left = 0;
  54.                 int right = 0;
  55.                 for (int j = 0; j < pil; j++)
  56.                 {
  57.                     for (int i = 0; i < 8; i++)
  58.                     {
  59.                         if (grid[i, j] == 1)
  60.                         {
  61.                             left++;
  62.                         }
  63.                     }
  64.                 }
  65.                 if (pil == 7 && left == 0)
  66.                 {
  67.                     win = true;
  68.                     break;
  69.                 }
  70.                 else if( pil == 7)
  71.                 {
  72.                     break;
  73.                 }
  74.                 for (int f = pil + 1; f < 8; f++)
  75.                 {
  76.                     for (int i = 0; i < 8; i++)
  77.                     {
  78.                         if (grid[i, f] == 1)
  79.                         {
  80.                             right++;
  81.                         }
  82.                     }
  83.                 }
  84.                 if (left == right)
  85.                 {
  86.                     result = left;
  87.                     win = true;
  88.                     break;
  89.                 }
  90.                 pil++;
  91.             }
  92.             // output
  93.             if (win)
  94.             {
  95.                 Console.WriteLine(7 - pil);
  96.                 Console.WriteLine(result);
  97.             }
  98.             else
  99.             {
  100.                 Console.WriteLine("No");
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment