PetyoPetrov

Programming Basics Exam 26 April 2015 Evening,ProbGameOFLife

Jan 12th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 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 row in oldboard)
  26.         {
  27.             Console.WriteLine(Convert.ToString(row, 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.Min(kol - 1, 0);
  47.                 for (int k = startred; k < endred; k++)
  48.                 {
  49.                     for (int l = endkol; l > startkol; l--)
  50.                     {
  51.                         if (k==red&&l==kol)
  52.                         {
  53.                             continue;
  54.                         }
  55.                         checkedbit = (oldboard[k]&(1<<l)) == 0 ? 0 : 1;
  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.                 }
  70.                 else
  71.                 {
  72.                     if (countones == 3)
  73.                     {
  74.                         newboard[red] |= (1 << kol);
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.  
  80.         Console.WriteLine(newboard[2]);  //pravq proverka kolko tretoto 4islo -zero testa dava razlika samo v nego
  81.  
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment