C++ 螺旋队列

#include <iostream> #include <iomanip> using namespace std; void fun(int x,int y) { if (x == y) cout<<setw(3)<< 2*x+(1-2*x)*(1-2*x)<<" "; if (x == -y+1 && x > 0) cout<<setw(3)<< 1+(1-2*x)*(1-2*x)<<" "; else if (x == -y+1 && x <= 0) cout<<setw(3)<< 4*y-1+(1-2*y)*(1-2*y)<<" "; else if (x > 0 && x > y && x > 1-y) //最右边一列 cout<<setw(3)<< x+y+(1-2*x)*(1-2*x)<<" "; else if (y<0 && x >y && x < 1-y) //最上面一行 cout<<setw(3)<< x+y+(1-2*y)*(1-2*y)<<" "; else if (y > 0 && x < y && x > 1-y) //最下面一行 cout<<setw(3)<< -x+3*y+(1-2*y)*(1-2*y)<<" "; else if (x < 0 && x < y && x < 1-y) //最左边一列 cout<<setw(3)<< 3*x-y+(1-2*x)*(1-2*x)<<" "; } int main () { for (int i = -5; i < 6; i++) { for (int j = -5; j < 6; j++) { fun(i,j); } cout<<endl; } return 0; }  

你可能感兴趣的:(C++ 螺旋队列)