Skip to content

Instantly share code, notes, and snippets.

@nasko90
Created December 9, 2016 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasko90/8e3e7f7fecaca29e8c1e73bab2f2da2e to your computer and use it in GitHub Desktop.
Save nasko90/8e3e7f7fecaca29e8c1e73bab2f2da2e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pinguin_Airlains
{
class Program
{
static void Main(string[] args)
{
string rc = Console.ReadLine();
int[] RC = rc.Split('x').Select(n => Convert.ToInt32(n)).ToArray();
int rows = RC[0];
int cols = RC[1];
char[,] cave = new char [rows,cols] ;
bool hitRock = false;
int lenght = 3;
int count = 0;
Cordinats startingPoint = new Cordinats(0, 0);
for (int i = 0; i < rows; i++)
{
string str = Console.ReadLine();
for (int j = 0; j < cols; j++)
{
cave[i, j] = str[j];
if (cave[i,j].Equals('e'))
{
startingPoint.x=i;
startingPoint.y = j;
}
}
}
char[] instructions = ConvertInstructions(Console.ReadLine());
for (int i = 0; i < instructions.Length; i++)
{
count++;
if (count % 5 == 0)
{
lenght--;
}
switch (instructions[i])
{
case 's': startingPoint.x = startingPoint.x+1;break;
case 'w': startingPoint.x = startingPoint.x - 1; break;
case 'a': startingPoint.y = startingPoint.y -1; break;
case 'd': startingPoint.y = startingPoint.y +1; break;
}
if (startingPoint.y > cols - 1)
{
startingPoint.y = 0;
}
if (startingPoint.y < 0)
{
startingPoint.y = cols - 1;
}
if (startingPoint.x > rows - 1)
{
Console.WriteLine("Sneaky is going to be lost into the depths with length {0}", lenght);
break;
}
switch (cave[startingPoint.x, startingPoint.y])
{
case '@': lenght++; cave[startingPoint.x, startingPoint.y] = '-' ; break;
case '%': Console.WriteLine("Sneaky is going to hit a rock at [{0},{1}]", startingPoint.x, startingPoint.y);hitRock = true; ;break ;
case 'e': Console.WriteLine("Sneaky is going to get out with length {0}", lenght);hitRock=true ;break;
default:break;
}
if (hitRock)
{
break;
}
if (lenght<=0)
{
Console.WriteLine("Sneaky is going to starve at [{0},{1}]", startingPoint.x, startingPoint.y);break;
}
if (i==instructions.Length-1)
{
Console.WriteLine("Sneaky is going to be stuck in the den at [{0},{1}]",startingPoint.x,startingPoint.y);
break;
}
}
}
static char[] ConvertInstructions(string str)
{
str = str.Replace(",", "");
char[] rows = str.ToCharArray();
return rows;
}
public class Cordinats
{
public int x;
public int y;
public Cordinats (int x,int y)
{
this.x = x;
this.y = y;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment