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 hheq121 at 2009-04-23 18:25:18 on Problem 1835
#include<iostream>
using namespace std;
int x,y,z;
int dir,dis;
char com[10];
int head;
void change()
{
	if(strcmp(com,"forward")==0)
	{
		switch(dir)
		{
			case 0:
				x+=dis;
				break;
			case 1:
				y+=dis;
				break;
			case 2:
				z+=dis;
				break;
			case 3:
				x-=dis;
				break;
			case 4:
				y-=dis;
				break;
			case 5:
				z-=dis;
				break;
		}
		return ;
		
	}
	if(strcmp(com,"back")==0)
	{
		switch(dir)
		{
			case 0:
				x-=dis;
				break;
			case 1:
				y-=dis;
				break;
			case 2:
				z-=dis;
				break;
			case 3:
				x+=dis;
				break;
			case 4:
				y+=dis;
				break;
			case 5:
				z+=dis;
				break;
		}
		dir=(dir+3)%6;
		return ;				
	}
	if(strcmp(com,"left")==0)
	{
		switch(dir)
		{
			case 0:
				if(head==2)
				{
					y-=dis;
					dir=4;
				}
				if(head==5)
				{
					y+=dis;
					dir=1;
				}
				if(head==1)
				{
					z+=dis;
					dir=2;
				}
				if(head==4)
				{
					z-=dis;
					dir=5;
				}
				break;
				
			case 1:
				if(head==2)
				{
					x+=dis;
					dir=0;
				}
				if(head==5)
				{
					x-=dis;
					dir=3;
				}
				if(head==0)
				{
					z-=dis;
					dir=5;
				}
				if(head==3)
				{
					z+=dis;
					dir=2;
				}
				break;
			case 2:
				if(head==0)
				{
					y+=dis;
					dir=1;
				}
				if(head==3)
				{
					y-=dis;
					dir=4;
				}
				if(head==1)
				{
					x-=dis;
					dir=3;
				}
				if(head==4)
				{
					x+=dis;
					dir=0;
				}
				break;
			case 3:
				if(head==1)
				{
					z-=dis;
					dir=5;
				}
				if(head==4)
				{
					z+=dis;
					dir=2;
				}
				if(head==2)
				{
					y+=dis;
					dir=1;
				}
				if(head==5)
				{
					y-=dis;
					dir=4;
				}
				break;
			case 4:
				if(head==0)
				{
					z+=dis;
					dir=2;
				}
				if(head==3)
				{
					z-=dis;
					dir=5;
				}
				if(head==2)
				{
					x-=dis;
					dir=3;
				}
				if(head==5)
				{
					x+=dis;
					dir=0;
				}

				break;
			case 5:
				if(head==0)
				{
					y-=dis;
					dir=4;
				}
				if(head==3)
				{
					y+=dis;
					dir=1;
				}
				if(head==1)
				{
					x+=dis;
					dir=0;
				}
				if(head==4)
				{
					x-=dis;
					dir=3;
				}
				break;
		}
		return ;		
	}
	if(strcmp(com,"right")==0)
	{
		switch(dir)
		{
			case 0:
				if(head==2)
				{
					y+=dis;
					dir=1;
				}
				if(head==5)
				{
					y-=dis;
					dir=4;	
				}
				if(head==1)
				{
					z-=dis;
					dir=5;
				}
				if(head==4)
				{
					z+=dis;
					dir=2;	
				}
				break;
				
			case 1:
				if(head==2)
				{
					x-=dis;
					dir=3;
				}
				if(head==5)
				{
					x+=dis;
					dir=0;					

				}
				if(head==0)
				{
					z+=dis;
					dir=2;
				}
				if(head==3)
				{
					z-=dis;
					dir=5;					
				}
				break;
			case 2:
				if(head==0)
				{
					y-=dis;
					dir=4;
				}
				if(head==3)
				{
					y+=dis;
					dir=1;	
				}
				if(head==1)
				{
					x+=dis;
					dir=0;
				}
				if(head==4)
				{
					x-=dis;
					dir=3;					
				}
				break;
			case 3:
				if(head==1)
				{
					z+=dis;
					dir=2;
				}
				if(head==4)
				{
					z-=dis;
					dir=5;					
				}
				if(head==2)
				{
					y-=dis;
					dir=4;
				}
				if(head==5)
				{
					y+=dis;
					dir=1;					
				}
				break;
			case 4:
				if(head==0)
				{
					z-=dis;
					dir=5;
				}
				if(head==3)
				{
					z+=dis;
					dir=2;					
				}
				if(head==2)
				{
					x+=dis;
					dir=0;
				}
				if(head==5)
				{
					x-=dis;
					dir=3;					
				}

				break;
			case 5:
				if(head==0)
				{
					y+=dis;
					dir=1;
				}
				if(head==3)
				{
					y-=dis;
					dir=4;					
				}
				if(head==1)
				{
					x-=dis;
					dir=3;
				}
				if(head==4)
				{
					x+=dis;
					dir=0;					
				}
				break;
		}
		return ;			
	}
	if(strcmp(com,"up")==0)
	{
		
		switch(dir)
		{
			case 0:
				if(head==2)
					z+=dis;
				if(head==5)
					z-=dis;
				if(head==1)
					y+=dis;
				if(head==4)
					y-=dis;
				break;
			case 1:
				if(head==0)
					x+=dis;
				if(head==3)
					x-=dis;
				if(head==2)
					z+=dis;
				if(head==5)
					z-=dis;
				break;
			case 2:
				if(head==0)
					x+=dis;
				if(head==3)
					x-=dis;
				if(head==1)
					y+=dis;
				if(head==4)
					y-=dis;
				break;
			case 3:
				if(head==1)
					y+=dis;
				if(head==4)
					y-=dis;
				if(head==2)
					z+=dis;
				if(head==5)
					z-=dis;
				break;
			case 4:
				if(head==0)
					x+=dis;
				if(head==3)
					x-=dis;
				if(head==2)
					z+=dis;
				if(head==5)
					z-=dis;
				break;
			case 5:
				if(head==0)
					x+=dis;
				if(head==3)
					x-=dis;
				if(head==1)
					y+=dis;
				if(head==4)
					y-=dis;
				break;
		}
		int tempdir=dir;
		dir=head;	
		head=(tempdir+3)%6;
		return ;
		
	}
	if(strcmp(com,"down")==0)
	{
		
		switch(dir)
		{
			case 0:
				if(head==2)
					z-=dis;
				if(head==5)
					z+=dis;
				if(head==1)
					y-=dis;
				if(head==4)
					y+=dis;
				break;
			case 1:
				if(head==0)
					x-=dis;
				if(head==3)
					x+=dis;
				if(head==2)
					z-=dis;
				if(head==5)
					z+=dis;
				break;
			case 2:
				if(head==0)
					x-=dis;
				if(head==3)
					x+=dis;
				if(head==1)
					y-=dis;
				if(head==4)
					y+=dis;
				break;
			case 3:
				if(head==1)
					y-=dis;
				if(head==4)
					y+=dis;
				if(head==2)
					z-=dis;
				if(head==5)
					z+=dis;
				break;
			case 4:
				if(head==0)
					x-=dis;
				if(head==3)
					x+=dis;
				if(head==2)
					z-=dis;
				if(head==5)
					z+=dis;
				break;
			case 5:
				if(head==0)
					x-=dis;
				if(head==3)
					x+=dis;
				if(head==1)
					y-=dis;
				if(head==4)
					y+=dis;
				break;
		}
		int temphead=head;
		head=dir;
		dir=(temphead+3)%6;
		return ;
				
	}

}
int main()
{
	int t;	
	scanf("%d",&t);
	while(t--)
	{
		int i,n;
		scanf("%d",&n);	
		x=0;y=0;z=0;dir=0;head=2;
		for(i=0;i<n;i++)
		{
			scanf("%s %d",com,&dis);
			change();
		}
		printf("%d %d %d %d\n",x,y,z,dir);
	}
	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