这种代码看起来很费事。给你提供一个顺时针旋转、纯计算的的作参考……
#include "stdafx.h"
#include "stdio.h"
#define max(a,b) ((a)<(b) ? (b) : (a))
#define abs(a) ((a)>0 ? (a) : -(a))
int foo(int x,int y){
int t=max(abs(x),abs(y));
int u=t+t;
int v=u-1;
v=v*v+u;
if(x==-t) v+=u+t-y;
else if(y==-t) v+=3*u+x-t;
else if(y==t) v+=t-x;
else v+=y-t;
return v;
}
void main(void){
int x,y;
for(y=-4;y<=4;y++){
for(x=-4;x<=4;x++)
printf("%4d",foo(x,y));
printf("\n");
}
while(scanf("%d%d",&x,&y)==2)
printf("%d\n",foo(x,y));
}