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. tcp协议和udp协议的使用场景

      一:什么是TCP(Transmission Control Protocol,传输控制协议) tcp是面向连接的协议,也就是说,在收发数据前,必须和对方建立可靠的连接.一个TCP连接必须要经过三次 ...

  2. 得到当前对象在不同大小的页面中的绝对位置,及冒泡cancelBubble

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. mysql 忽略某个错误 继续执行

    执行如下存储过程: CREATE  PROCEDURE `aa`()BEGINcall RealtimeData_9035();call RealtimeData_9504();call Realti ...

  4. DataSnap高级技术(7)—TDSServerClass中Lifecycle生命周期三种属性说明

    From http://blog.csdn.net/sunstone/article/details/5282666 DataSnap高级技术(7)—TDSServerClass中Lifecycle生 ...

  5. WINRAR 自解压脚本命令及变量

    自解压脚本命令 Path=d:\ ;绝对路径 ;Path=.\在当前文件夹中创建 ;Path=在“Program Files”中创建 ;在当前文件夹创建,无语句 Setup=释放后运行 Presetu ...

  6. WDA-FPM-3-SEARCH(OIF)

    转载:https://www.cnblogs.com/sapSB/p/10097830.html   FPM三:简单的SEARCH(OIF) 这里是使用FPM Workbench自动生成的,没有去SE ...

  7. vue-webpack 引入echarts 注意事项

    0.执行教程 https://www.cnblogs.com/goloving/p/8654176.html1.在index 中创建 div <!DOCTYPE html> <htm ...

  8. 移动cup

    intel处理器M和U H结尾的有什么具体区别 笔记本CPU 酷睿i 系列U M H详解: U 低压版(低电压-性能消减)最低主频:1.7-1.9GHZ M 准电压(笔记本上的电压标准)最低主频:2. ...

  9. 基元线程同步构造之信号量(Semaphore)

    信号量(semaphore)不过是由内核维护的 int32变量而已,(说通俗点就是好比一个线程容器里面允许执行的线程数,0计数就是允许执行的0个线程数,1就是允许执行的1个线程数,2就是允许执行的2个 ...

  10. python Count类(转)

    1.collections模块 collections模块自Python 2.4版本开始被引入,包含了dict.set.list.tuple以外的一些特殊的容器类型,分别是: OrderedDict类 ...