标签:des style class blog c code
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
代码
1 //注意题意,左手位置和上方位置一直在变啊 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 int x,y,z,s,up,left; 8 struct ss{ 9 char d[20]; 10 int num; 11 }; 12 void der(int num){ 13 14 switch(s){ 15 case 0 : x += num;break; 16 case 1 : y += num;break; 17 case 2 : z += num;break; 18 case 3 : x -= num;break; 19 case 4 : y -= num;break; 20 case 5 : z -= num;break; 21 } 22 //printf("x:%d y:%d z:%d s:%d\n",x,y,z,s); 23 } 24 void ice(char str[],int num){ 25 26 if(strcmp(str,"back") == 0){ 27 left = (left+3) % 6; 28 s = (s+3) % 6; 29 } 30 else if(strcmp(str,"left") == 0){ 31 int k = s; 32 s = left; 33 left = (k+3) % 6; 34 } 35 else if(strcmp(str,"right") == 0){ 36 int k = s; 37 s = (left+3) % 6; 38 left = k; 39 } 40 else if(strcmp(str,"up") == 0){ 41 int k = up; 42 up = (s+3) % 6; 43 s = k; 44 } 45 else if(strcmp(str,"down") == 0){ 46 int k = up; 47 up = s; 48 s = (k+3) % 6; 49 } 50 der(num); 51 } 52 int main(){ 53 int n,m; 54 ss op[10004]; 55 scanf("%d",&m); 56 while(m --){ 57 x = y = z = s = 0; 58 left = 4; 59 up = 2; 60 scanf("%d",&n); 61 for(int i = 1; i <= n; i ++){ 62 scanf("%s%d",op[i].d,&op[i].num); 63 ice(op[i].d,op[i].num); 64 } 65 printf("%d %d %d %d\n",x,y,z,s); 66 67 } 68 return 0; 69 }
模拟--poj1835宇航员的故事,布布扣,bubuko.com
标签:des style class blog c code
原文地址:http://www.cnblogs.com/aSeven/p/3750655.html