Chinaunix首页 | 论坛 | 博客
  • 博客访问: 35977
  • 博文数量: 7
  • 博客积分: 206
  • 博客等级: 入伍新兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-29 18:24
文章分类
文章存档

2015年(1)

2013年(1)

2012年(1)

2011年(3)

2010年(1)

我的朋友

分类: C/C++

2010-09-29 18:27:08

// 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;
}
 
阅读(667) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:识别符的引用符是反勾号(‘`’)

给主人留下些什么吧!~~