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 sunflowwer at 2007-05-19 12:18:57 on Problem 1835
#include <stdio.h>
#include <string.h>

struct word{
	 int top;
	 int face;
	 int x,y,z;
}mapa;
struct direction{
     int left;
	 int right;
}map[5][5];
int ab(int a)
{
    if(a<0)
		return -a;
	return a;
}
int work(char str[10])
{
	int s;
	s=0;
    if(strcmp(str,"left")==0){
		if(mapa.top<0)
			++s;
		else if(mapa.face<0)
			++s,mapa.face=-mapa.face;
		if(s%2==0)
			mapa.face=map[ab(mapa.top)][mapa.face].left;
		else if(s%2)
			mapa.face=-map[ab(mapa.top)][mapa.face].left;
	}
	else if(strcmp(str,"right")==0){
	    if(mapa.top<0)
			++s;
		else if(mapa.face<0)
			++s,mapa.face=-mapa.face;
		if(s%2==0)
			mapa.face=map[ab(mapa.top)][mapa.face].right;
		else if(s%2)
			mapa.face=-map[ab(mapa.top)][mapa.face].right;
	}
	return 0;
}
int little(int face,int length)
{
    if(ab(face)==1)
		mapa.x+=face*length/ab(face);
	else if(ab(face)==2)
		mapa.y+=face*length/ab(face);
	else if(ab(face)==3)
		mapa.z+=face*length/ab(face);
	return 0;
}
int main()
{
	int i,j,m,n;
	char str[10];
	int length;
	int x,y;
	int temp;
	scanf("%d",&m);
	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			map[i+1][j+1].left=100,map[i+1][j+1].right=100;
	map[3][1].left=-2;
	map[1][2].left=-3;
	map[2][3].left=-1;
	for(i=0;i<3;i++)
		for(j=0;j<3;j++){
		    x=i+1;
			y=j+1;
			if(map[x][y].left!=100)
				map[x][y].right=-map[x][y].left;
			else if(map[x][y].right!=100)
				map[x][y].left=-map[x][y].right;
			else if(map[y][x].left!=100)
				map[x][y].left=-map[y][x].left,
				map[x][y].right=-map[x][y].left;
			else if(map[y][x].right!=100)
				map[x][y].right=-map[y][x].right,
				map[x][y].left=-map[x][y].right;
		}
/*    for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			printf("map[%d][%d].left=%d map[%d][%d].right=%d\n",i+1,j+1,map[i+1][j+1].left,i+1,j+1,map[i+1][j+1].right);*/
	while(m--)
    {
	     scanf("%d",&n);
		 mapa.top=3;
		 mapa.face=1;
		 mapa.x=0;
		 mapa.y=0;
		 mapa.z=0;
		 while(n--)
		 {
			  scanf("%s%d",&str,&length);
			  if(strcmp(str,"forward")==0)
				  little(mapa.face,length);
			  else if(strcmp(str,"back")==0){
				  mapa.face=-mapa.face;
				  little(mapa.face,length);
			  }
			  else if(strcmp(str,"up")==0){
				  temp=mapa.top;
			      mapa.top=-mapa.face;
				  mapa.face=temp;
				  little(mapa.face,length);
			  }
			  else if(strcmp(str,"down")==0){
			      temp=mapa.top;
				  mapa.top=mapa.face;
				  mapa.face=-temp;
				  little(mapa.face,length);
			  }
			  else if(strcmp(str,"left")==0){
			      work(str);
				  little(mapa.face,length);
			  }
			  else if(strcmp(str,"right")==0){
			      work(str);
				  little(mapa.face,length);
			  }
		 }
		 printf("%d %d %d ",mapa.x,mapa.y,mapa.z);
		 if(mapa.face>0)
			printf("%d\n",mapa.face-1);
		 else if(mapa.face<0)
			printf("%d\n",-mapa.face-1+3);
	}
	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