本帖最后由 番杰 于 2021-11-11 16:07 编辑 #include<stdio.h>
#define WHILE 0 //修改宏定义为1时,可以循环输入指令
int x = 0,y = 0;
void Com_x(int ,int ,int);
void main(void)
{
int i = 0;
#if WHILE
while(1)
{
#endif
printf("input the command:");
scanf("%d %d %d",&x,&y,&i);
switch(i)
{
case 1: x -= 1;printf("%d %d",x,y);break;
case 2: x += 1;printf("%d %d",x,y);break;
case 3: y += 1;printf("%d %d",x,y);break;
case 4: y -= 1;printf("%d %d",x,y);break;
case 5: y = 0-y;printf("%d %d",x,y);break;
case 6: x = 0-x;printf("%d %d",x,y);break;
case 7: x = 0-x;y = 0-y;printf("%d %d",x,y);break;
case 8: Com_x(x,y,8);printf("%d %d",x,y);break;
case 9: Com_x(x,y,9);printf("%d %d",x,y);break;
default : printf("input the correct command,please");break;
}
#if WHILE
}
#endif
}
void Com_x(int x1,int y1,int com)
{
if(x1>=0 && y1 >= 0)//第一象限
{
if(com == 8) //逆时针
{
x = 0-y1;
y = x1;
}
else //顺时针
{
x = y1;
y = 0-x1;
}
}
else if(x1 < 0 && y1 >= 0)//第二象限
{
if(com == 8)//逆时针
{
y = 0-x1;
x = y1;
}
else //顺时针
{
x = 0-y1;
y = x1;
}
}
else if(x1 < 0 && y1 < 0)//第三象限
{
if(com == 8)//逆时针
{
y = 0-x1;
x = y1;
}
else //顺时针
{
x = 0-y1;
y = x1;
}
}
else if(x1 >= 0 && y1 < 0)//第四象限
{
if(com == 8)//逆时针
{
y = x1;
x = 0-y1;
}
else //顺时针
{
x = y1;
y = 0-x1;
}
}
}
|