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 huangjing1987 at 2009-08-23 17:59:08 on Problem 1573
#include<iostream>
using namespace std;
int main()
{
	char d[100][100];
	int a,b,c,x1[100],y1[100];
	int x=0,y=0,num=0,tap;
	cin>>a>>b>>c;
	for(int i=0;i<a;i++)
	{
		cin>>d[i];
	}
	while(a!=0||b!=0||c!=0)
	{
		x=0;y=c-1;
		x1[0]=0;
		y1[0]=y;
		while(1)
		{

			if(d[x][y]=='N')
			{x=x-1;}
			else if(d[x][y]=='S')
			{x=x+1;}
			else if(d[x][y]=='W')
			{y=y-1;}
			else if(d[x][y]=='E')
			{y=y+1;}
			num++;
			x1[num]=x;
			y1[num]=y;

			if(x<0||x>=a||y<0||y>=b)
			{
				cout<<num<<" step(s) to exit"<<endl;
				break;
			}
			for(int j=0;j<num-1;j++)
			{
				if(x1[j]==x&&y1[j]==y)
				{
					cout<<j<<" step(s) before a loop of "<<num-j<<" step(s)"<<endl;
					tap=1;
					break;
				}
				
			}
			if(tap==1)
			{
				tap=0;
				break;
			}
		}
		num=0;
		cin>>a>>b>>c;
		for(int i=0;i<a;i++)
		{
			cin>>d[i];
		}
		x=0;y=c-1;
		x1[0]=0;
		y1[0]=y;
	}
	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