Hi Guys I novice at programming and solve simple problems such spoj.com/problems/HFLOOR/ from tutorial.
On this problem I am getting, runtime error (NZEC). Below is my program, tell me, please, the test for which it does not work.
#! /usr/bin/env python
from sys import stdin
def getdata(sp, i, j, people):
sp[i][j] = "#"
if sp[i + 1][j] == "*" or sp[i + 1][j] == "-":
if sp[i + 1][j] == "*":
people += 1
sp[i + 1][j] = "#"
people = getdata(sp, i + 1, j, people)
if sp[i][ j + 1] == "*" or sp[i][j + 1] == "-":
if sp[i][j + 1] == "*":
people += 1
sp[i][j + 1] = "#"
people = getdata(sp, i, j + 1, people)
if sp[i - 1][j] == "*" or sp[i - 1][j] == "-":
if sp[i - 1][j] == "*":
people += 1
sp[i - 1][j] = "#"
people = getdata(sp, i - 1, j, people)
if sp [i][j - 1] == "*" or sp[i][j - 1] == "-":
if sp[i][j - 1] == "*":
people += 1
sp[i][j - 1] = "#"
people = getdata(sp, i, j - 1, people)
return people
a = int(input())
for _ in xrange(a):
m, n = map(int, stdin.readline().split())
sp = []
for i in xrange(m):
line = map (str, stdin.readline().split())
st = line[0]
temp = []
for j in xrange(n):
temp.append(st[j])
sp.append(temp)
room = 0
people = 0
for i in xrange(m):
for j in xrange(n):
if sp[i][j] == "*" or sp[i][j] == "-":
if sp[i][j] == "*":
people += 1
room += 1
people = getdata(sp, i, j, people)
if room == 0:
print "0.00"
else:
print ("%.2f" % round(float(people)/room, 2))