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

为什么wa!!实在是无语了。。。

Posted by hustar at 2008-11-08 01:36:49 on Problem 1573
#include <stdio.h>
#include <string.h>
int main()
{
	int r, c, cntx, cnty, i, j, ans, flag;
	int step[20][20];
	char map[20][20];
	while(scanf("%d%d%d%*c",&r,&c,&cnty)&&r)
	{
		for(i=1;i<=r;i++)
		{
			for(j=1;j<=c;j++)
				map[i][j]=getchar();
			getchar();
		}
		memset(step,0,sizeof(step));
		ans=1;
		cntx=1;
		flag=0;
		while(1)
		{
			switch(map[cntx][cnty])
			{
			case 'E': cnty++;break;
			case 'W': cnty--;break;
			case 'N': cntx--;break;
			case 'S': cntx++;break;
			}
			if(!(cntx>=1&&cntx<=r&&cnty>=1&&cnty<=c)) break;
			else if(step[cntx][cnty])
			{
				flag=1;
				break;
			}
			else 
			{
				ans++;
				step[cntx][cnty]=ans;
			}
		}
		if(flag)
			printf("%d step(s) before a loop of %d step(s)\n",step[cntx][cnty]-1,ans-step[cntx][cnty]+1);
		else printf("%d step(s) to exit\n",ans);
	}
	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