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

老是说我Runtime Error,都不知道错在哪里,郁闷。

Posted by springtty at 2005-10-12 18:10:55 on Problem 2632
#include <stdio.h>
#include <string.h>
#define maxsize 120

struct Instruction
{
	int ID;
	char Dir;
	int rep;
};

struct Robet
{
	int ID;
	int i,j;
	char Dir;
};
char ddir[4] = {'N','E','S','W'};

char GetDir(char InsDir,char CurDir)
{
	int i;
	for(i=0;i<4;i++)
		if(CurDir == ddir[i]) break;
	if(InsDir == 'L')	return ddir[(i-1+4)%4];
	else if(InsDir == 'R')	return ddir[(i+1)%4];
	
	return CurDir;
}

int main()
{
	int A,B,N,M;
	int times;
	int i,j;
	int rep;
	int ID;
	char d;
	int row,col;
	int type = 0;
	int lastID;
	int m,e;
	
	int Map[maxsize][maxsize];
	struct Instruction Ins[maxsize];
	struct Robet Hash[maxsize];

	scanf("%d",&times);

	while(times)
	{
		memset(Map,0,maxsize*maxsize*sizeof(int));
		memset(Ins,0,maxsize*sizeof(Instruction));
		memset(Hash,0,maxsize*sizeof(Robet));
		
		scanf("%d %d",&A,&B);
		scanf("%d %d",&N,&M);
		
		type = 0;
		for(i=1;i<=N;i++)
		{
			scanf("%d %d %c",&Hash[i].i,&Hash[i].j,&Hash[i].Dir);
			Hash[i].i = B - Hash[i].i + 1;
			Hash[i].ID = i;
			Map[Hash[i].i][Hash[i].j] = i;
		}

		for(i=1;i<=M;i++)
		{
			scanf("%d %c %d",&Ins[i].ID,&Ins[i].Dir,&Ins[i].rep);
		}
		
		for(i=1;i<=M;i++)
		{
			ID = Ins[i].ID;
			d = Ins[i].Dir;
			rep = Ins[i].rep;
			row = Hash[ID].i;
			col = Hash[ID].j;			
			
			if(Ins[i].Dir != 'F')
			{
			
				 m = rep % 4;
				for( e=0;e<m;e++)
				{
					d = GetDir(Ins[i].Dir,Hash[ID].Dir);
					Hash[ID].Dir = d;
				}
				continue;
			} 
			else
			{
				for(j=1;j<=rep;j++)
				{
					Map[row][col] = 0;

					switch(Hash[ID].Dir)
					{
						case 'E': col++;break;
						case 'W': col--;break;
						case 'N': row--;break;
						case 'S': row++;break;
					}

					if(row<1 || row > B || col <1 || col > A)	
					{
						type = 1;
						break;
					}

					if(Map[row][col]!=0)	
					{
						type = 2;
						lastID =  Map[row][col];
						break;
					}
				
					Map[row][col] = ID;
					Hash[ID].i = row;
					Hash[ID].j = col;
					
			}/*for rep*/
				if(type!=0)	break;
		
		}/*else if forward*/
				
		}/*for exec ins */
				if(type == 1)	printf("Robot %d crashes into the wall\n",ID);
				else if(type == 2) printf("Robot %d crashes into robot %d\n",ID,lastID);
				else printf("OK\n");

		times--;
	}
	
	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