stefan1919

CollectTheCoins

Sep 22nd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.39 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 ConsoleApplication7
  8. {
  9.     class Program
  10.     {
  11.        
  12.         static void Main(string[] args)
  13.         {
  14.             char[] firstLine = Console.ReadLine().ToArray();
  15.             char[] secondLine = Console.ReadLine().ToArray();
  16.             char[] thirdLine = Console.ReadLine().ToArray();
  17.             char[] fourthLine = Console.ReadLine().ToArray();
  18.             char[] input = Console.ReadLine().ToArray();
  19.             char[][] jagged = new char[4][] { firstLine, secondLine, thirdLine, fourthLine };
  20.             int currentRow = 0;
  21.             int currentCol = 0;
  22.             int coinsCounter = 0;
  23.             int wallsCounter = 0;
  24.             for (int i = 0; i < input.Length; i++)
  25.             {
  26.                
  27.                 if (input[i] == 'V')
  28.                 {
  29.                     //if V
  30.                     if (currentRow == 0)
  31.             {
  32.                 if (currentCol < secondLine.Length)
  33.                 {
  34.                     currentRow++;
  35.                     if (jagged[currentRow][currentCol] == '$')
  36.                     {
  37.                         coinsCounter++;
  38.                     }
  39.                     continue;
  40.                 }
  41.                 else
  42.                 {
  43.                     wallsCounter++;
  44.                     continue;
  45.                 }
  46.             }
  47.             if (currentRow == 1)
  48.             {
  49.                 if (currentCol < thirdLine.Length)
  50.                 {
  51.                     currentRow++;
  52.                     if (jagged[currentRow][currentCol] == '$')
  53.                     {
  54.                         coinsCounter++;
  55.                        
  56.                     }
  57.                     continue;
  58.                 }
  59.                 else
  60.                 {
  61.                     wallsCounter++;
  62.                     continue;
  63.                 }
  64.             }
  65.             if (currentRow == 2)
  66.             {
  67.                 if (currentCol < fourthLine.Length)
  68.                 {
  69.                     currentRow++;
  70.                     if (jagged[currentRow][currentCol] == '$')
  71.                     {
  72.                         coinsCounter++;
  73.                        
  74.                     }
  75.                     continue;
  76.                 }
  77.                 else
  78.                 {
  79.                     wallsCounter++;
  80.                     continue;
  81.                 }
  82.             }
  83.             if (currentRow == 3)
  84.             {
  85.                 wallsCounter++;
  86.                 continue;
  87.             }
  88.                
  89.                 }//if = V/
  90.                 //if >
  91.                 if (input[i] == '>')
  92.                 {
  93.                     if (currentRow == 0)
  94.             {
  95.                 if (currentCol < firstLine.Length)
  96.                 {
  97.                     currentCol++;
  98.                     if (jagged[currentRow][currentCol] == '$')
  99.                        
  100.                     {
  101.                         coinsCounter++;
  102.                        
  103.                     }
  104.                     continue;
  105.                 }
  106.                 else
  107.                 {
  108.                     wallsCounter++;
  109.                     continue;
  110.                 }
  111.                
  112.             }
  113.             if (currentRow == 1)
  114.             {
  115.                 if (currentCol < secondLine.Length)
  116.                 {
  117.                     currentCol++;
  118.                     if (jagged[currentRow][currentCol] == '$')
  119.                     {
  120.                         coinsCounter++;
  121.                        
  122.                     }
  123.                     continue;
  124.                 }
  125.                 else
  126.                 {
  127.                     wallsCounter++;
  128.                     continue;
  129.                 }
  130.             }
  131.             if (currentRow == 2)
  132.             {
  133.                 if (currentCol < thirdLine.Length)
  134.                 {
  135.                     currentCol++;
  136.                     if (jagged[currentRow][currentCol] == '$')
  137.                     {
  138.                         coinsCounter++;
  139.                        
  140.                     }
  141.                     continue;
  142.                 }
  143.                 else
  144.                 {
  145.                     wallsCounter++;
  146.                     continue;
  147.                 }
  148.             }
  149.             if (currentRow == 3)
  150.             {
  151.                if (currentCol < fourthLine.Length)
  152.                 {
  153.                     currentCol++;
  154.                     if (jagged[currentRow][currentCol] == '$')
  155.                     {
  156.                         coinsCounter++;
  157.                        
  158.                     }
  159.                     continue;
  160.                 }
  161.                 else
  162.                 {
  163.                     wallsCounter++;
  164.                     continue;
  165.                 }
  166.             }
  167.             }
  168.                 //if >/
  169.                 //if <
  170.                 if (input[i] == '<')
  171.                 {
  172.                     if (currentCol != 0)
  173.                     {
  174.                         currentCol--;
  175.                     if (jagged[currentRow][currentCol] == '$')
  176.                     {
  177.                         coinsCounter++;
  178.                        
  179.                     }
  180.                     continue;
  181.                     }
  182.                     else
  183.                     {
  184.                         wallsCounter++;
  185.                         continue;
  186.                     }
  187.                 }//if </
  188.                 if (input[i] == '^')
  189.                 {
  190.                    if (currentRow == 0)
  191.             {
  192.                 wallsCounter++;
  193.                 continue;
  194.             }
  195.             if (currentRow == 3)
  196.             {
  197.                 if (currentCol < thirdLine.Length)
  198.                 {
  199.                     currentRow--;
  200.                     if (jagged[currentRow][currentCol] == '$')
  201.                     {
  202.                         coinsCounter++;
  203.                        
  204.                     }
  205.                     continue;
  206.                 }
  207.                 else
  208.                 {
  209.                     wallsCounter++;
  210.                     continue;
  211.                 }
  212.             }
  213.             if (currentRow == 2)
  214.             {
  215.                 if (currentCol < secondLine.Length)
  216.                 {
  217.                     currentRow--;
  218.                     if (jagged[currentRow][currentCol] == '$')
  219.                     {
  220.                         coinsCounter++;
  221.                        
  222.                     }
  223.                     continue;
  224.                 }
  225.                 else
  226.                 {
  227.                     wallsCounter++;
  228.                     continue;
  229.                 }
  230.             }
  231.             if (currentRow == 1)
  232.             {
  233.                 if (currentCol < firstLine.Length)
  234.                 {
  235.                     currentRow--;
  236.                     if (jagged[currentRow][currentCol] == '$')
  237.                     {
  238.                         coinsCounter++;
  239.                        
  240.                     }
  241.                     continue;
  242.                 }
  243.                 else
  244.                 {
  245.                     wallsCounter++;
  246.                     continue;
  247.                 }
  248.             }
  249.                 }
  250.             }//enf for
  251.             Console.WriteLine("Coins collected:");
  252.             Console.WriteLine(coinsCounter);
  253.             Console.WriteLine("Walls hit:");
  254.             Console.WriteLine(wallsCounter);
  255.         }
  256.         }
  257. }
Advertisement
Add Comment
Please, Sign In to add comment