标签:
Time Limit: 2000MS | Memory Limit: 30000K | |
Total Submissions: 4866 | Accepted: 2077 |
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
Source
思路:先表示出初始状态,正面=0,左面=4,上面=2,随着坐标的变化,这三个面的相对关系也跟随着变化
#include<stdio.h> int main() { int n,i; scanf("%d",&n); while(n--) { char str[11]; int face=0,left=4,head=2,temp,x=0,y=0,z=0,d,m; scanf("%d",&m); for(i=0;i<m;i++) { scanf("%s%d",str,&d); if(str[0]==‘b‘) { face=(face+3)%6;//加3在对6取余就是这个方向的相反方向。 left=(left+3)%6; } else if(str[0]==‘l‘) { temp=face; face=left; left=(temp+3)%6; } else if(str[0]==‘r‘) { temp=left; left=face; face=(temp+3)%6; } else if(str[0]==‘u‘) { temp=face; face=head; head=(temp+3)%6; } else if(str[0]==‘d‘) { temp=head; head=face; face=(temp+3)%6; } if(face==0) x+=d; if(face==1) y+=d; if(face==2) z+=d; if(face==3) x-=d; if(face==4) y-=d; if(face==5) z-=d; } printf("%d %d %d %d\n",x,y,z,face); } }
标签:
原文地址:http://www.cnblogs.com/tianmin123/p/4626412.html