• 九宫格扩展,输入一个奇数,得到横竖斜相加相等结果


      static   public int[,] NineNumSort(int num)
            {
                int[,] arynum = new int[num, num];
                int max = num - 1;
                int x = 0;
                int y = 0;
                arynum[x, num / 2] = 1;
                y = num / 2;
                for (int i = 2; i <= num * num; i++)
                {
                    if (x == 0)
                    {
                        if (y + 1 <= max)
                        {
                            arynum[max, y + 1] = i;
                            y++;
                            x = max;
                            continue;
                        }
                        else
                        {
                            arynum[x + 1, max] = i;
                            x++;
                            y = max;
                            continue;
                        }
                    }
    
                    if (y == max)
                    {
                        arynum[x - 1, 0] = i;
                        x--;
                        y = 0;
                        continue;
                    }
    
                    if (arynum[x - 1, y + 1] != 0)
                    {
                        arynum[x + 1, y] = i;
                        x++;
                        continue;
                    }
                    else
                    {
                        arynum[x - 1, y + 1] = i;
                        x--;
                        y++;
                        continue;
                    }
                }
                return arynum;
            }

    输入一个奇数,得到一个正方形  横向竖向斜向 相加相等的 function

    author by:可乐

  • 相关阅读:
    靶机练习
    靶机练习
    靶机练习
    CTF-攻防世界-Web_php_unserialize(PHP反序列化)
    漏洞复现
    靶机练习
    靶机练习
    靶机练习
    糗事集合
    慕课前端入门-JS事件
  • 原文地址:https://www.cnblogs.com/fish124423/p/2526682.html
Copyright © 2020-2023  润新知