螺旋队列

螺旋矩阵:要求输入(x,y),输出螺旋矩阵中相应的元素。

int printfSpiralMatrix(int x,int y)
    {
        int Max = abs(x) > abs(y) ? abs(x) : abs(y);
        int Result;
        if (Max == x)          // x 正半轴
        {
            if (Max == -y)     //会突变
                Result = pow((Max * 2 + 1), 2);
            else
                Result = pow((Max * 2 - 1), 2) + Max + y;
        }
        else if (Max == -x)    // x 负半轴
            Result = pow((Max * 2 - 1), 2) + 5 * Max - y;
        else if (Max == y)     // y 正半轴
            Result = pow((Max * 2 - 1), 2) + 3 * Max - x;
        else                   // y 负半轴
            Result = pow((Max * 2 - 1), 2) + 7 * Max + x;
        return Result;
    }
打印螺旋矩阵中某一个元素
原文地址:https://www.cnblogs.com/shihaochangeworld/p/5679756.html