本题要求将n*n个自然数按蛇型方式存放在二位数组A[n][n]中蛇型方式即是按副对角线平行的各对角线从左下到右上再从右上到左下存放n个整数对角线共n条在副对角线上方的对角线题目中用k表示第k条对角线(最左上角k=)数组元素x和y方向坐标之和为k+(即题目中的i+j=k+)副对角线下方第k条对角线与第nk条对角线对称其元素的下标等于其对称元素的相应坐标各加(kn)
()k<=*n //共填*n条对角线
()q=*nk //副对角线以下的各条对角线上的元素数
()k%!= //k为偶数时从右上到左下否则从左下向右上填数(本处计算下标i和j)
()k>=n //修改副对角线下方的下标i和j
()m++或m=m+ //为填下个数作准备m变化范围n*n
本题解法的另一种思路见本章算法设计题第题
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []