Advertisement
stanevplamen

02.09.03.03.KukataDancing

Jun 22nd, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.24 KB | None | 0 0
  1. using System;
  2.  
  3. class KukataDancing
  4. {
  5.     static string[,] theMatrix;
  6.  
  7.     static int length = 3;
  8.  
  9.     static void LoadTheMatrix()
  10.     {
  11.         theMatrix = new string[3, 3];
  12.         for (int row = 0; row < length; row++)
  13.         {
  14.             for (int col = 0; col < length; col++)
  15.             {
  16.                 // edge
  17.                 if ((col == 0 && row == 0) || (col == 0 && row == length - 1) || (col == length - 1 && row == 0) || (col == length - 1 && row == length - 1))
  18.                 {
  19.                     theMatrix[row, col] = "RED";
  20.                 }
  21.                 // center
  22.                 else if (col == 1 && row == 1)
  23.                 {
  24.                     theMatrix[row, col] = "GREEN";
  25.                 }
  26.                 // other
  27.                 else
  28.                 {
  29.                     theMatrix[row, col] = "BLUE";
  30.                 }
  31.             }          
  32.         }
  33.     }
  34.  
  35.     //static string tempString;
  36.  
  37.     static void DanceImplementation(string currentDance, int currentCol, int currentRow, int currentDirCol, int currentDirRow, int lastStep, bool col, int i)
  38.     {
  39.         if (currentRow >= length)
  40.         {
  41.             currentRow = 0;
  42.         }
  43.         else if (currentRow < 0)
  44.         {
  45.             currentRow = length - 1;
  46.         }
  47.         if (currentCol >= length)
  48.         {
  49.             currentCol = 0;
  50.         }
  51.         else if (currentCol < 0)
  52.         {
  53.             currentCol = length - 1;
  54.         }
  55.  
  56.         string tempString = theMatrix[currentRow, currentCol];
  57.  
  58.         if (i >= currentDance.Length )
  59.         {
  60.            Console.WriteLine(tempString);
  61.            return;
  62.         }
  63.  
  64.             if (currentDance[i] == 'L')
  65.             {
  66.                 if (col == true)
  67.                 {
  68.                     if (currentDirCol == 1)
  69.                     {
  70.                         lastStep = i;
  71.                         currentDirCol = 0;
  72.                         currentDirRow = -1;
  73.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, false, i + 1);
  74.                     }
  75.                     else if (currentDirCol == -1)
  76.                     {
  77.                         lastStep = i;
  78.                         currentDirCol = 0;
  79.                         currentDirRow = 1;
  80.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, false, i + 1);
  81.                     }
  82.                    
  83.                 }
  84.                 else if (col == false)
  85.                 {
  86.                     if (currentDirRow == 1)
  87.                     {
  88.                         lastStep = i;
  89.                         currentDirCol = 1;
  90.                         currentDirRow = 0;
  91.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, true, i + 1);
  92.                     }
  93.                     else if (currentDirRow == -1)
  94.                     {
  95.                         lastStep = i;
  96.                         currentDirCol = -1;
  97.                         currentDirRow = 0;
  98.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, true, i + 1);
  99.                     }
  100.                    
  101.                 }
  102.             }
  103.             else if (currentDance[i] == 'R')
  104.             {
  105.                 if (col == true)
  106.                 {
  107.                     if (currentDirCol == 1)
  108.                     {
  109.                         lastStep = i;
  110.                         currentDirCol = 0;
  111.                         currentDirRow = 1;
  112.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, false, i + 1);
  113.                     }
  114.                     else if (currentDirCol == -1)
  115.                     {
  116.                         lastStep = i;
  117.                         currentDirCol = 0;
  118.                         currentDirRow = -1;
  119.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, false, i + 1);
  120.                     }
  121.                    
  122.                 }
  123.                 else if (col == false)
  124.                 {
  125.                     if (currentDirRow == 1)
  126.                     {
  127.                         lastStep = i;
  128.                         currentDirCol = -1;
  129.                         currentDirRow = 0;
  130.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, true, i + 1);
  131.                     }
  132.                     else if (currentDirRow == -1)
  133.                     {
  134.                         lastStep = i;
  135.                         currentDirCol = 1;
  136.                         currentDirRow = 0;
  137.                         DanceImplementation(currentDance, currentCol, currentRow, currentDirCol, currentDirRow, lastStep, true, i + 1);
  138.                     }
  139.                    
  140.                 }
  141.             }
  142.             else if (currentDance[i] == 'W')
  143.             {
  144.                 if (col == true)
  145.                 {
  146.                     lastStep = i;
  147.                     DanceImplementation(currentDance, currentCol + currentDirCol, currentRow, currentDirCol, currentDirRow, lastStep, true, i + 1);                  
  148.                 }
  149.                 else if (col == false)
  150.                 {
  151.                     lastStep = i;
  152.                     DanceImplementation(currentDance, currentCol, currentRow + currentDirRow, currentDirCol, currentDirRow, lastStep, false, i + 1);                    
  153.                 }
  154.             }
  155.             return;
  156.     }
  157.  
  158.     static string[] dances;
  159.  
  160.     static void Main()
  161.     {
  162.         string input = Console.ReadLine(); //"5"; //
  163.         int numberOfDances = int.Parse(input);
  164.         dances = new string[numberOfDances];
  165.         for (int i = 0; i < dances.Length; i++)
  166.         {
  167.             dances[i] = Console.ReadLine();
  168.         }
  169.  
  170.         LoadTheMatrix();
  171.  
  172.         for (int i = 0; i < dances.Length; i++)
  173.         {
  174.             DanceImplementation(dances[i], 1, 1, 0, 1, -1, false, 0);
  175.             // DanceImplementation(dances[i], currentCol, currentRow, currentDirCol, currentDirRow, lastStep, col, counter);
  176.         }
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement