- 9
- 0
- 约 4页
- 2017-06-07 发布于重庆
- 举报
C螺旋(右上三角)加蛇形(左下三角)矩阵(数组)
C#螺旋(右上三角)加蛇形(左下三角)矩阵(数组)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int n ;
Console.Write(请输入一个数:);
n = Int32.Parse(Console.ReadLine());
int t = n;
int max = n * n;
int row = 0, col = 0;
int m = (max - n) / 2 + n;//螺旋的最大值
int[,] result = new int[t, t];
bool flag = true;//对角标志
for (int i = 1; i = m; i++)
{//螺旋部分
if ((flag result[row, col n ? col : n - 1] == 0))
{//横向螺旋
result[row, col] = i;
col++;
continue;
}
if (flag (result[row n - 1 ? row + 1 : n - 1, col - 1] == 0))
{//纵向螺旋
row++;
result[row, col - 1] = i;
continue;
}
//对角斜向上
if (flag)
col--;
flag = false;
col--;
row--;
result[row, col] = i;
if (result[row - 1 0 ? 0 : row - 1, col - 1 0 ? 0 : col - 1] == 0)
{//斜对角数未填充
continue;
}
else
{
if (result[row, col + 1] != 0)
{
continue;
}
else
{
col++;
flag = true;
}
}
}
row = 1;
col = 0;
n = t;
flag = true;
for (int i = m + 1; i = max; i++)
{//蛇形部分
if (flag result[row = n ? n - 1 : row, col = n - 2 ? n - 2 : col] == 0)
{//斜向下对角
您可能关注的文档
- 高中语文必修三第三单元测试.docx
- 高中语文教学论文小组合作学习在语文教学中的运用.doc
- 高中语文教学论文把探究信息技术带进语文教学.doc
- 高中语文综合检测.doc
- 高中音乐教案).doc
- 高二(下)5月考生物试卷(含答案).doc
- 高二_热学.doc
- 高二上化学期中(临沂).doc
- 高二上化学期中(临淄).doc
- 高二中段理科数学试题.doc
- 2026年及未来5年内中国液体氩气行业投资前景及策略咨询研究报告.docx
- 2026年及未来5年内中国黄铜合页行业投资前景及策略咨询研究报告.docx
- 2026年及未来5年内中国竹工艺家具行业投资前景及策略咨询研究报告.docx
- 2025年中国微机数显自动分析仪市场调查研究报告.docx
- 2026年及未来5年内中国微尘白色粉笔行业投资前景及策略咨询研究报告.docx
- 2025年中国微电脑型压胶机市场调查研究报告.docx
- 2026年及未来5年内中国数字化等功游泳训练测试系统行业投资前景及策略咨询研究报告.docx
- 2025年中国圆形花瓶市场调查研究报告.docx
- 2026年及未来5年内中国植物纤维静淀过滤器行业投资前景及策略咨询研究报告.docx
- 2025年中国超音波手套机市场调查研究报告.docx
原创力文档

文档评论(0)