OJ-上海交大-1021. 从前有座山

进程间通信的方式

题目链接:
https://acm.sjtu.edu.cn/OnlineJudge/problem/1021
编程语言:python

import sys
num = int(sys.stdin.readline());
lines = [];
for i in range(num):
    lines.append(range(num));
i = 0;
j = 0;
count = 1;
cishu = 0;
while count <= num*num:
    j = cishu;
    i = cishu;
    while j < num - cishu:
        lines[i][j] = count;
        count = count + 1;
        j = j +1;
    j -= 1;
    i += 1;
    while i < num - cishu:
        lines[i][j] = count;
        count += 1;
        i+=1;
    i -= 1;
    j -= 1;
    while j >= 0 + cishu:
        lines[i][j] = count;
        count+= 1;
        j -= 1;
    j+=1;
    i -= 1;
    while i > cishu:
        lines[i][j] = count;
        count +=1;
        i -= 1;
    i += 1;
    j += 1;
    cishu += 1;
for i in range(num):
    for j in range(num):
        sys.stdout.write(str(lines[i][j]));
        sys.stdout.write(" ");
    sys.stdout.write("\n");


转载请注明原文地址,谢谢。


posted @ 2016-12-30 18:15  程小白  阅读(539)  评论(0编辑  收藏  举报