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
Imports System
Imports Microsoft.VisualBasic
Module Zombi
Const InputFile As String = "zombi.be"
Const OutputFile As String = "zombi.ki"
Const Ures As Integer = 0
Const Fal As Integer = -1
Const Zombi As Integer = -2
Private N, M As Integer
Private tomb(,) As Integer
Private zombik(,) As Boolean
Private Sub Beolvas()
Dim sor As String
FileOpen(1, InputFile, OpenMode.Input, OpenAccess.Read)
Input(1, N)
Input(1, M)
ReDim tomb(N + 1, M + 1), zombik(N + 1, M + 1)
For i As Integer = 1 To N
sor = LineInput(1)
For j As Integer = 1 To M
Select Case sor.Chars(j - 1)
Case " "c
tomb(i, j) = Ures
Case "#"c
tomb(i, j) = Fal
Case "Z"c
tomb(i, j) = Zombi
End Select
Next
Next
For i As Integer = 0 To N + 1
For j As Integer = 0 To M + 1
If i = 0 Or j = 0 Or i = N + 1 Or j = M + 1 Then
tomb(i, j) = Fal
End If
zombik(i, j) = (tomb(i, j) = Zombi)
Next
Next
FileClose(1)
End Sub
Private Sub Bejar(ByVal i As Integer, ByVal j As Integer, ByVal elozo As Integer)
If zombik(i, j) Then elozo += 1
If tomb(i, j) = Ures OrElse tomb(i, j) = Zombi OrElse tomb(i, j) > elozo + 1 Then
tomb(i, j) = elozo + 1
Bejar(i - 1, j, elozo + 1)
Bejar(i + 1, j, elozo + 1)
Bejar(i, j - 1, elozo + 1)
Bejar(i, j + 1, elozo + 1)
End If
End Sub
Private Sub ElozoLepes(ByVal i As Integer, ByVal j As Integer)
If i <> 1 Or j <> 1 Then
If tomb(i - 1, j) > 0 And tomb(i - 1, j) < tomb(i, j) Then
ElozoLepes(i - 1, j)
ElseIf tomb(i + 1, j) > 0 And tomb(i + 1, j) < tomb(i, j) Then
ElozoLepes(i + 1, j)
ElseIf tomb(i, j - 1) > 0 And tomb(i, j - 1) < tomb(i, j) Then
ElozoLepes(i, j - 1)
ElseIf tomb(i, j + 1) > 0 And tomb(i, j + 1) < tomb(i, j) Then
ElozoLepes(i, j + 1)
End If
PrintLine(1, i.ToString() & " " & j.ToString())
Else
PrintLine(1, "1 1")
End If
End Sub
Private Sub Kiir()
FileOpen(1, OutputFile, OpenMode.Output, OpenAccess.Write)
WriteLine(1, tomb(N, M))
ElozoLepes(N, M)
FileClose(1)
End Sub
Public Sub Main()
Beolvas()
Bejar(1, 1, 0)
Kiir()
End Sub
End Module