胖总是个大大傻逼

# $language = "Python"
# $interface = "1.0"

# Connect to a telnet server and automate the initial login sequence.
# Note that synchronous mode is enabled to prevent server output from
# potentially being missed.
def my_backshape(n):
  x_director = [0,1,0,-1]
  y_director = [1,0,-1,0]
  i = 0
  j = -1
  flag = 0
  result = 1
  matrix = [[0 for col in range(n)] for row in range(n)]

  while (flag == 0):
    flag = 1
    for k in range(-1,4):
      temp_x = i + x_director[k]
      temp_y = j + y_director[k]
      while(temp_x<n and temp_y<n and temp_x>-1 and temp_y>-1 and matrix[temp_x][temp_y]==0 ):
        matrix[temp_x][temp_y] = result
        flag = 0
        i = temp_x
        j = temp_y
        temp_x = temp_x + x_director[k]
        temp_y = temp_y + y_director[k]
        result = result + 1

  for i in range(n):
    for j in range(n):
      print "%-4d"%(matrix[i][j]),
    print " "
my_backshape(4)

猜你喜欢

转载自passionke.iteye.com/blog/2255792