题目如下:
代码如下:
#include<stdio.h>
#define SIZE 50
void input(int*a,int *b,int get_command);
void pen(int main_command,int x,int y,int floor[][SIZE]);
void print_array(int floor[][SIZE],int SIZE);
int main()
{
int floor[SIZE][SIZE]={0};
// 定位
int x=0,y=0;
int main_command=1;
int base_command=0;
int get_command=0;
int right_count=0;
int left_count=0;
int *a=&main_command;
int *b=&base_command;
while ( get_command!= 9){
scanf("%d",&get_command);
input(*a,*b,get_command);
switch(base_command){
case 3:
right_count++;
break;
case 4:
left_count++;
break;
case 5:
int gap =left_count - right_count;
int move;
scanf("%d",&move);
//判断头的朝向
switch(gap % 4){
case 0:
for(int count=0;count<move;count++){
x--;
pen(main_command,x,y,floor);
}
break;
case -3:
case 1:
for(int count=0;count<move;count++){
y--;
pen(main_command,x,y,floor);
}
break;
case -2:
case 2:
for(int count=0;count<move;count++){
y++;
pen(main_command,x,y,floor);
}
break;
case -1:
case 3:
for(int count=0;count<move;count++){
x++;
pen(main_command,x,y,floor);
}
break;
}
break;
case 6:
print_array(floor,SIZE);
}
}
return 0;
}
void input(int*a,int *b,int get_command){
if(get_command==1 ||get_command==2){
*a=get_command;
}else{
*b=get_command;
}
}
void pen(int main_command,int x,int y,int floor[][SIZE]){
if(main_command == 1){
floor[x][y]=1;
}
}
void print_array(int floor[][SIZE],int SIZE){
puts("This Routine is:");
for(int i=0;i<SIZE ;i++){
for(int j=0;j<SIZE;j++){
if(floor[i][j]==1){
printf("*");
}else{
printf(" ");
}
printf("%d ",floor[i][j]);
if(j==49){
puts("");
}
}
}
}
编译器提示: