标签:
Description
Input
Output
Sample Input
1 6 left 10 right 11 up 12 down 13 forward 14 back 15
Sample Output
23 -10 12 3
#include <iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; int t,n,step,dir,up,rgt; int a[10]; char ch[10]; int main() { scanf("%d",&t); for(;t>0;t--) { dir=0; up=2; rgt=1;//先确定1.面向的方向,2.头顶方向,3.右边的方向 memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s%d",&ch,&step); if (ch[0]==‘f‘) a[dir]+=step; else if (ch[0]==‘b‘) {dir=(dir+3)%6; rgt=(rgt+3)%6; a[dir]+=step;} else if (ch[0]==‘l‘) {int t=dir; dir=(rgt+3)%6; rgt=t; a[dir]+=step;} else if (ch[0]==‘r‘) {int t=dir; dir=rgt; rgt=(t+3)%6; a[dir]+=step;} else if (ch[0]==‘u‘) {int t=dir; dir=up; up=(t+3)%6; a[dir]+=step;} else if (ch[0]==‘d‘) {int t=dir; dir=(up+3)%6; up=t; a[dir]+=step;} } printf("%d %d %d %d\n",a[0]-a[3],a[1]-a[4],a[2]-a[5],dir); } return 0; }
标签:
原文地址:http://www.cnblogs.com/stepping/p/5815005.html