Skip to content

Instantly share code, notes, and snippets.

@Svetomech
Created September 12, 2017 18:50
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 Svetomech/cd8d3f8365fbc40b39f8af4fa66e07e7 to your computer and use it in GitHub Desktop.
Save Svetomech/cd8d3f8365fbc40b39f8af4fa66e07e7 to your computer and use it in GitHub Desktop.
"There is no Spoon - Episode 1" CodinGame solution
using System;
class Player
{
static void Main(string[] args)
{
int width = int.Parse(Console.ReadLine());
int height = int.Parse(Console.ReadLine());
var grid = new char[width, height];
for (int i = 0; i < height; i++)
{
string line = Console.ReadLine();
for (int j = 0; j < width; j++)
{
grid[j, i] = line[j];
}
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (grid[j, i] == '.') continue;
int right = j;
while (++right < width && grid[right, i] == '.');
string rightNeighbour = right < width && (grid[right, i] != '.') ? $"{right} {i}" : "-1 -1";
int down = i;
while (++down < height && grid[j, down] == '.');
string downNeighbour = down < height && (grid[j, down] != '.') ? $"{j} {down}" : "-1 -1";
Console.WriteLine($"{j} {i} {rightNeighbour} {downNeighbour}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment