Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

苊的代码应该很好理解!分享!

Posted by madrishing at 2012-05-27 11:15:30 on Problem 1835
#include<iostream>
using namespace std;
int T,n,cnt,x,y,z;
char str[20];
void go(int dir){
	switch(dir){
		case 0:x+=cnt;break;
		case 1:y+=cnt;break;
		case 2:z+=cnt;break;
		case 3:x-=cnt;break;
		case 4:y-=cnt;break;
		case 5:z-=cnt;break;
		default:break;
	}
}
int main(){
	int dir,head,tmp,left;//各个方向不解释
	cin>>T;
	while(T--){
		cin>>n;
		x=y=z=dir=0,head=2,left=4;
		while(n--){
			cin>>str>>cnt;
			switch(str[0]){
				case'f':break;
				case'b':dir=(dir+3)%6,left=(left+3)%6;break;
				case'l':tmp=dir,dir=left,left=(tmp+3)%6;break;
				case'r':tmp=left,left=dir,dir=(tmp+3)%6;break;
				case'u':tmp=head,head=(dir+3)%6,dir=tmp;break;
				case'd':tmp=dir,dir=(head+3)%6,head=tmp;break;
				default:break;
			}
			go(dir);
		}
		cout<<x<<" "<<y<<" "<<z<<" "<<dir<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator