Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2350503
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:01:55

#include

using namespace std;

struct numUnit
{
int value;
int x;
int y;
};

int main(int argc, char* argv[] )
{
int num;

cout << "Enter a number:";
cin >> num;

numUnit matrixUnit[num*num];
int xMark, yMark;

for ( int iBas=1; iBas <= num; iBas++ ){
xMark = iBas;
yMark = 1;
matrixUnit[iBas-1].value = iBas;
matrixUnit[iBas-1].x = xMark;
matrixUnit[iBas-1].y = yMark;
};

int i = num + 1;
bool ypp = true;

for ( int j=(num-1); j >= 1; j-- ){
if ( ypp == true){
for ( int ky=1; ky <= j; ky++){
matrixUnit[i-1].value = i;
matrixUnit[i-1].x = xMark;
yMark++;
matrixUnit[i-1].y = yMark;
i++;
};
for ( int kx=1; kx <=j; kx++){
matrixUnit[i-1].value = i;
xMark--;
matrixUnit[i-1].x = xMark;
matrixUnit[i-1].y = yMark;
i++;
};
}
else {
for ( int ky=1; ky <= j; ky++){
matrixUnit[i-1].value = i;
matrixUnit[i-1].x = xMark;
yMark--;
matrixUnit[i-1].y = yMark;
i++;
};
for ( int kx=1; kx <=j; kx++){
matrixUnit[i-1].value = i;
xMark++;
matrixUnit[i-1].x = xMark;
matrixUnit[i-1].y = yMark;
i++;
};
};
ypp = (!ypp);
};

for ( int sy=1; sy <= num; sy++ ){
for ( int sx=1; sx <= num; sx++ ){
for ( int sn=1;sn <= num*num; sn++ ){
if ( matrixUnit[sn-1].x == sx && matrixUnit[sn-1].y == sy){
printf("%4d",matrixUnit[sn-1].value);
}
}
}
cout << endl;
};

return 0;
}


--------------------next---------------------
#include

using namespace std;

struct numUnit
{
int value;
int x;
int y;
};

int main(int argc, char* argv[] )
{
int num;

cout << "Enter a number:";
cin >> num;

numUnit matrixUnit[num*num];
int xMark, yMark;

for ( int iBas=1; iBas <= num; iBas++ ){
xMark = iBas;
yMark = 1;
matrixUnit[iBas-1].value = iBas;
matrixUnit[iBas-1].x = xMark;
matrixUnit[iBas-1].y = yMark;
};

int i = num + 1;
bool ypp = true;

for ( int j=(num-1); j >= 1; j-- ){
if ( ypp == true){
for ( int ky=1; ky <= j; ky++){
matrixUnit[i-1].value = i;
matrixUnit[i-1].x = xMark;
yMark++;
matrixUnit[i-1].y = yMark;
i++;
};
for ( int kx=1; kx <=j; kx++){
matrixUnit[i-1].value = i;
xMark--;
matrixUnit[i-1].x = xMark;
matrixUnit[i-1].y = yMark;
i++;
};
}
else {
for ( int ky=1; ky <= j; ky++){
matrixUnit[i-1].value = i;
matrixUnit[i-1].x = xMark;
yMark--;
matrixUnit[i-1].y = yMark;
i++;
};
for ( int kx=1; kx <=j; kx++){
matrixUnit[i-1].value = i;
xMark++;
matrixUnit[i-1].x = xMark;
matrixUnit[i-1].y = yMark;
i++;
};
};
ypp = (!ypp);
};

for ( int sy=1; sy <= num; sy++ ){
for ( int sx=1; sx <= num; sx++ ){
for ( int sn=1;sn <= num*num; sn++ ){
if ( matrixUnit[sn-1].x == sx && matrixUnit[sn-1].y == sy){
printf("%4d",matrixUnit[sn-1].value);
}
}
}
cout << endl;
};

return 0;
}


--------------------next---------------------

阅读(1197) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~