PetyoPetrov

Programming Basics Exam 26 April 2015 Evening,ProbGameOFLife

Jan 13th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 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.  
  8. class Program
  9. {
  10.     static void Main()
  11.     {
  12.         int pairs = int.Parse(Console.ReadLine());
  13.         int[] oldboard = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
  14.         int x; int y;
  15.         List<int> newboard = new List<int>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  16.        // List<int> coordinates = new List<int>();
  17.         for (int i = 0; i < pairs; i++)
  18.         {
  19.             x = int.Parse(Console.ReadLine());
  20.             y = int.Parse(Console.ReadLine());
  21.             oldboard[x] |= (1 << y);
  22.             //coordinates.Add(x);
  23.             //coordinates.Add(y);
  24.         }
  25.         //foreach (var s in oldboard)
  26.         //{
  27.         //    Console.WriteLine(Convert.ToString(s, 2).PadLeft(10, '0'));
  28.         //}
  29.  
  30.         for (int red =0; red < 10; red++)// minavam prez vcseki edin bit
  31.         {
  32.             //foreach (var row in newboard)
  33.             //{
  34.             //    Console.WriteLine(Convert.ToString(row, 2).PadLeft(10, '0'));
  35.             //}
  36.             Console.WriteLine();
  37.             for (int kol = 9; kol >=0; kol--)
  38.             {
  39.                
  40.                 int currentbit = (oldboard[red] & (1 << kol)) == 0 ? 0 : 1;
  41.                 int checkedbit;
  42.                 int countones = 0;
  43.                 int startred = Math.Max(red - 1, 0);// opredelqv koi susedni bitove da proverqvam
  44.                 int endred = Math.Min(red + 1, 9);
  45.                 int startkol = Math.Min(kol + 1, 9);
  46.                 int endkol = Math.Max(kol - 1, 0);
  47.                 for (int k = startred; k <= endred; k++)
  48.                 {
  49.                     for (int l = startkol; l >= endkol; l--)
  50.                     {
  51.                         if (k==red&&l==kol)
  52.                         {
  53.                             continue;
  54.                         }
  55.                         checkedbit = (oldboard[k]&(1<<l)) != 0 ? 1 : 0;
  56.                         if (checkedbit==1)
  57.                         {
  58.                             countones++;
  59.                         }
  60.                     }
  61.                 }
  62.  
  63.                 if (currentbit == 1)
  64.                 {
  65.                     if (countones < 2 || 3 < countones)
  66.                     {
  67.                         newboard[red] &= ~(1 << kol);
  68.                     }
  69.                     else
  70.                     {
  71.                         newboard[red] |= (1 << kol);
  72.                     }
  73.                 }
  74.                 else
  75.                 {
  76.                     if (countones == 3)
  77.                     {
  78.                         newboard[red] |= (1 << kol);
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.  
  84.         //Console.WriteLine(Convert.ToString(newboard[2],2));//pravq proverka kolko tretoto 4islo -zero testa dava razlika samo v nego
  85.         foreach (var row in newboard)
  86.         {
  87.             Console.WriteLine(Convert.ToString(row, 2).PadLeft(10, '0'));
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment