西单


私信TA

用户名:uq_61408358601

访问量:1754

签 名:

等  级
排  名 12678
经  验 905
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:根据当前位置坐标判断下一步行走方向和所要改变的位置颜色。(交流学习:1490707770)

注意事项:

参考代码:

#include<stdio.h> 

int *p,*f;

char *asp;

void left(char *asp)

{

if(*asp=='L')

{

*asp='D';}

else if(*asp=='D')

*asp='R';

else if(*asp=='R')

*asp='U';

else if(*asp=='U')

*asp='L';

}

void  right(char *asp)

{if(*asp=='L')

*asp='U';

else if(*asp=='U')

*asp='R';

else if(*asp=='R')

*asp='D';

else if(*asp=='D')

*asp='L';

}

int staus(int *p,int *f,char *asp)

{

if(*asp=='L')

*f=*f-1;

else if(*asp=='D')

*p=*p+1;

else if(*asp=='R')

*f=*f+1;

else if(*asp=='U')

*p=*p-1;

return 0; 

}


int step(int *p,int *f,char *asp,int k,int a[100][100] )

{

for(int t=0;t<k;t++)

{

if(a[*p][*f]==0)

{a[*p][*f]=1;

left(asp);

staus(p,f,asp);}

else

{a[*p][*f]=0;

right(asp);

staus(p,f,asp);} }

printf("%d %d",*p,*f);

return 0;

}




int main()

{ int a[100][100],c,x,y,b,k;

char aspect,blank;

scanf("%d%d",&b,&c);

for(int i=0;i<b;i++)

for(int j=0;j<c;j++)

scanf("%d",&a[i][j]);

scanf("%d %d %c %d",&x,&y,&aspect,&k);

p=&x;

f=&y;

asp=&aspect;

step(p,f,asp,k,a);

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区