Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 2 KB
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace labirintus {
class vect2d {
public int x;
public int y;
}
class Program {
public static bool[,] data;
public static bool[,] data2;
public static int n;
static void Main(string[] args)
{
StreamReader sr = new StreamReader("lab15.txt");
n = Int32.Parse(sr.ReadLine())+2;
data = new bool[n, n];
data2 = new bool[n, n];
for (int i = 0; i < n; i++)
{
string s = sr.ReadLine();
for (int k = 0; k < n; k++)
{
if (s[k] != ' ') {
data[i, k] =
true;
data2[i, k] =
true;
}
}
}
sr.Close();
for (; ; )
{
bool volt = false;
for (int i = 1; i < n - 1; i++)
{
for (int k = 1; k < n - 1; k++)
{
if (data[i, k]) continue;
int counter = 0;
if (data[i - 1, k]) counter++;
if (data[i + 1, k]) counter++;
if (data[i, k - 1]) counter++;
if (data[i, k + 1]) counter++;
if (counter > 2)
{
data[i, k] =
true;
volt =
true;
}
}
}
if (!volt) break;
}
output();
Console.ReadKey(true);
vect2d now = new vect2d();
now.x = 0;
now.y = 1;
vect2d last = new vect2d();
last.x = now.x;
last.y = now.y;
data[1, 0] =
true;
for (; ; )
{
bool volt = false;
for (int i = 1; i < n - 1; i++)
{
for (int k = 1; k < n - 1; k++)
{
if (data[i, k]) continue;
int counter = 0;
if (data[i - 1, k]) counter++;
if (data[i + 1, k]) counter++;
if (data[i, k - 1]) counter++;
if (data[i, k + 1]) counter++;
if (counter > 2)
{
data[i, k] =
true;
volt =
true;
now.x = k;
now.y = i;
if(now.x == last.x){
if(now.y > last.y){
Console.WriteLine("LE");
}
else {
Console.WriteLine("FEL");
}
}
if(now.y == last.y){
if(now.x > last.x){
Console.WriteLine("JOBBRA");
}
else {
Console.WriteLine("BALRA");
}
}
last.x = now.x;
last.y = now.y;
}
}
}
if (!volt) break;
}
Console.WriteLine("JOBBRA");
Console.ReadKey(true);
}
static void output()
{
for (int i = 0; i < n; i++)
{
for (int k = 0; k < n; k++)
{
if (!data[i, k]) Console.Write("*");
else if (data2[i, k]) Console.Write("#");
else Console.Write(" ");
}
Console.WriteLine();
}
}
static void dump() {
for (int i = 0; i < n; i++)
{
for (int k = 0; k < n; k++)
{
if (data[i, k]) Console.Write("#");
else Console.Write(" ");
}
Console.WriteLine();
}
}
}
}