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: 4 KB
using System;
using System.IO;
namespace psz_100105
{
class Program
{
public static void Main(string[] args)
{
StreamReader sr = new StreamReader("lab05.txt");
int meret = int.Parse(sr.ReadLine())+2;
char[,] labi = new char[meret,meret];
int a, b;
string sor;
for(a=0;a<meret;a++){
sor = sr.ReadLine();
for(b=0;b<meret;b++){
labi[a,b]=sor[b];
if((a==0|b==0|a==meret-1|b==meret-1)&&labi[a,b]==' '){
labi[a,b]='Q';
}
}
}
bool vaneharom=true;
int hanyszomszed;
while(vaneharom){
vaneharom=false;
for(a=1;a<meret-1;a++){
for(b=1;b<meret-1;b++){
hanyszomszed=0;
if(labi[a,b]==' '){
if(labi[a-1,b]=='#'){hanyszomszed++;};
if(labi[a,b-1]=='#'){hanyszomszed++;};
if(labi[a+1,b]=='#'){hanyszomszed++;};
if(labi[a,b+1]=='#'){hanyszomszed++;};
}
if(hanyszomszed==3){
labi[a,b]='#';
vaneharom=true;
}
}
}
}
char irany='j';
labi[0,1]='#';
int pozx=1, pozy=1;
string ut = "E";
bool lepes=false;
while(labi[pozx,pozy]!='Q'){
labi[pozx,pozy]='Z';
if(labi[pozx+1,pozy]==' '&&lepes==false){
if(irany=='j'){ut+="J"; irany='l';}
if(irany=='b'){ut+="B"; irany='l';}
pozx++;
lepes=true;
}
if(labi[pozx-1,pozy]==' '&&lepes==false){
if(irany=='j'){ut+="B"; irany='f';}
if(irany=='b'){ut+="J"; irany='f';}
pozx--;
lepes=true;
}
if(labi[pozx,pozy+1]==' '&&lepes==false){
if(irany=='f'){ut+="J"; irany='j';}
if(irany=='l'){ut+="B"; irany='j';}
pozy++;
lepes=true;
}
if(labi[pozx,pozy-1]==' '&&lepes==false){
if(irany=='f'){ut+="B"; irany='b';}
if(irany=='l'){ut+="J"; irany='b';}
pozy--;
lepes=true;
}
if(labi[pozx,pozy+1]=='Q'){
ut+="E";
if(irany=='l'){ut+="B"; irany='b';}
pozy++;
}
ut+="E";
lepes=false;
}
StreamWriter sw = new StreamWriter("lab05.kiA");
sw.WriteLine(ut.Length);
sw.WriteLine(ut);
for(a=0;a<meret;a++){
for(b=0;b<meret;b++){
if(labi[a,b]=='#'){sw.Write(labi[a,b]);} else {sw.Write(".");};
}
sw.WriteLine();
}
sw.Close();
sr.Close();
}
}
}