一道很有趣的题目,考了小车的行动,同时要设置方向号来进行偏移方向
俺的做法:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main()
{
int x=0,y=0;
int dirtory=0;
char a[1000];
scanf("%s",a);
for(int i=0; a[i]!='\0'; i++)
{
switch(a[i])
{
case'L':
dirtory++;
dirtory=dirtory%4;
break;
case'R':
dirtory--;
dirtory=dirtory%4;
break;
case'P':
switch(dirtory)
{
case 0:
y++;
break;
case 1:
x--;
break;
case 2:
y--;
break;
case 3:
x++;
break;
case -1:
x++;
break;
case -2:
y--;
break;
case -3:
x--;
break;
}
}
}
printf("%d %d\n",x,y);
return 0;
}
标签:case,哪儿,++,小车,break,--,int,CP1061,dirtory
From: https://www.cnblogs.com/harumakigohan686/p/17051840.html