using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class Program
{
public static int[,] a = new int[7, 7];
public static int count = 0;
public static int row = 0;
public static int col = 0;
public static int RowMax = 6;
public static int RowMin = 0;
public static int ColMax = 6;
public static int ColMin = 0;
public static int shangzuo1 = 0;

public static bool c = false;
public static int p = 0;
public static int q = 0;
static void Main(string[] args)
{
digui();
int n = 7;
if(n%2!=0)
a[n / 2, n/ 2] = n*n;
for (int i = 0; i < 7; i++)
for (int j = 0; j < 7; j++)
{
Console.Write(a[i, j] + "\t");
if (j == 6)
Console.WriteLine();

}
Console.ReadLine();
}

public static void digui()
{

while (p == 0 && q == 0)
{
count++;
if (count > 49)
return;
if (c==true)
{
col++;
row++;
ColMin++;
ColMax--;
RowMin++;
RowMax--;
c = false;

}

if (col > ColMax)
{

q = 1;

col--;
count--;
if(count<49)

digui();

}
else
{

a[row, col] = count;
if (count == 49)
return;

col++;
}

}
while (p == 0 && q == 1)
{
count++;
if (count > 49)
return;

row++;
if (row > RowMax)
{

p = 1;

row--;
count--;
if (count < 49)
digui();

}
else
{
a[row, col] = count;
if (count == 49)
return;

}

}
while (p == 1 && q == 1)
{
count++;

if (count >49)
return;
col--;
if (col < ColMin)
{

q = 0;

col++;
count--;
if (count <49)
digui();

}
else
{

a[row, col] = count; if (count == 49)
return;

}

}
while (p == 1 && q == 0)
{
count++;
if (count >49)
return;
row--;

if (row < RowMin)
{

p = 0;
c = true;

row++;
count-=2;
if (count <49)
digui();

}
else
{

if(row>RowMin)
a[row, col] = count; if (count == 49)
return;

}

}
}
}
}

c#递归实现螺旋数组的更多相关文章

  1. 每天一个JavaScript实例-递归实现反转数组字符串

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. PHP实现螺旋矩阵(螺旋数组)

    今天碰到一个比较有意思的问题, 就是把A到Y这25个字母以下面的形式输出出来 A B C D E P Q R S F O X Y T G N W V U H M L K J I 问题很有意思,就是转圈 ...

  3. C语言 · 递归倒置字符数组

    算法提高 递归倒置字符数组   时间限制:1.0s   内存限制:512.0MB      问题描述 完成一个递归程序,倒置字符数组.并打印实现过程 递归逻辑为: 当字符长度等于1时,直接返回 否则, ...

  4. 用java实现螺旋数组

    接收数组的行数和列数,返回正序和倒序的螺旋数组 package cn.baokx; public class Test { public static void main(String[] args) ...

  5. Java实现 蓝桥杯VIP 算法提高 递归倒置字符数组

    算法提高 递归倒置字符数组 时间限制:1.0s 内存限制:512.0MB 问题描述 完成一个递归程序,倒置字符数组.并打印实现过程 递归逻辑为: 当字符长度等于1时,直接返回 否则,调换首尾两个字符, ...

  6. [leetcode]54. Spiral Matrix2生成螺旋数组

    import java.util.Arrays; /** * Created by lvhao on 2017/7/6. * Given an integer n, generate a square ...

  7. vue递归过滤树结构数组

    let arr=[{ title:'1', key:'1', type:0, children:[{ title:'1-1', key:'1-1', type:0, }] },{ title:'2', ...

  8. 基于Visual C++2013拆解世界五百强面试题--题3-打印螺旋数组

    请用C语言实现 输入N,打印N*N矩阵 比如 N = 3, 打印: 1 2 3 8 9 4 7 6 5 N = 4, 打印 1   2    3   4 12  13   14  5 11  16   ...

  9. php递归实现一维数组转为指定树状结构 --- 省市区处理

    ### 这两天脑壳痛,一时短路,想不到准备利用递归实现这个需求,最后还是要请教同事,回来自己在实现了一遍,并记录下来 ### 原数据: // { // 广东省: { // 广州市: [ // &quo ...

随机推荐

  1. uva146-枚举,排列

    题意: 输入最多150个小写字母,在字典序增大的方向,求下一个排列是什么. 模拟枚举,最后一个字符是递归的最后一层(n层),那么把它弹出栈(还剩n-1层),如果n-1层的字符比第n层小,说明把n层的字 ...

  2. https Configure a Spring Boot app for HTTPS on Amazon AWS.

    参考: https://geocolumbus.github.io/HTTPS-ELB-AWS-Spring-Boot/ 1.  在服务器端配置  证书 域名 映射 2. 导入依赖: <depe ...

  3. Firemonkey 绘图 TPathData

    Firemonkey  TPathData TPath控件 procedure TForm12.FormPaint( Sender : TObject; Canvas : TCanvas; const ...

  4. Spring Boot学习--项目启动时执行特定方法

    Springboot给我们提供了两种"开机启动"某些方法的方式:ApplicationRunner和CommandLineRunner. 这两种方法提供的目的是为了满足,在项目启动 ...

  5. c++ vector, 迭代器

    现代c++尽量使用vector(容器)和迭代器(相当于指针),少使用数组和指针,除非对程序执行效率有很高的要求. 容器优点,易于扩展,可通过push_back方法动态添加元素,数组不能动态添加元素. ...

  6. python帮助信息查看以及笔记

    如何获取使用帮助: 获取对象支持使用的属性和方法:dir() dir()不带参数时,返回当前范围内的变量.方法和定义的类型列表:带参数时,返回参数的属性.方法列表.如果参数包含方法__dir__(), ...

  7. shell中的条件判断以及与python中的对比

    shell中比如比较字符串.判断文件是否存在及是否可读等,通常用"[]"来表示条件测试. 注意:这里的空格很重要.要确保方括号的空格. if ....; then          ...

  8. Java中的默认构造函数

    java中如果在一个类中没有写明任何构造函数的,那么会存在一个无参的构造函数,如下: public class Children { private String name; private Stri ...

  9. SQL语句查询年龄分段分组查询

    此情况用于数据库中没有“年龄”这个字段,只有“出生日期”这个字段.先计算出“年龄”,在分组查询. 1.SELECT *, ROUND(DATEDIFF(CURDATE(), popBirthday)/ ...

  10. select top 变量问题

    1.拼接查询语句(SQL2000,2005,2008均可) DECLARE @a AS INT SET @a=1 EXEC('SELECT TOP '+@a+' * FROM mtrcLanguage ...