`
passionke
  • 浏览: 20622 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

胖总可以吃的自助餐

 
阅读更多

# $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 = 0
  matrix = [[0 for col in range(n)] for row in range(n)]

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

my_backshape(4)

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics