// out.cpp: 主项目文件。
#include "stdafx.h"
#include "stdio.h"
using namespace System;
int main(array ^args)
{
//Console::WriteLine(L"Hello World");
//1 2 3 4 5
//16 17 18 19 6
//15 24 25 20 7
//14 23 22 21 8
//13 12 11 10 9
#define MAXLEN 10
int temp[MAXLEN][MAXLEN] = {0};
int val = 0;
int len = MAXLEN;
int imax = MAXLEN;
int imin = 0;
int row = 0, col = 0;
bool bStep = true;
for(int once = 0; once < len; once++)
{
if(bStep)
{
while(col < imax || row+1 < imax)
{
val++;
if(col < imax)
{
temp[imin][col++] = val;
}else
temp[++row][imax-1] = val;
}
imax--;
col--;
row--;
}else{
while(col >imin || row > imin)
{
val++;
if(col > imin)
{
temp[imax][--col] = val;
}else
temp[row--][imin] = val;
}
imin++;
col++;
row++;
}
bStep = !bStep;
}
for(int x = 0; x < len; x++)
{
for(int y = 0; y < len; y++)
printf("%4d ", temp[x][y]);
printf("\n");
}
return 0;
}
阅读(697) | 评论(0) | 转发(0) |