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

纪念AC!

Posted by bjtu1 at 2008-10-04 22:40:00 on Problem 1573
#include<stdio.h>
#include<memory.h>


char smap[12][12];
int map[12][12];

int main()
{
	int r,c,start;
	int i,total;
	int x,y;
	int flag;


	while(scanf("%d%d%d",&r,&c,&start)!=EOF){
		if(r==0&&c==0&&start==0)
			return 0;
		memset(map,0,sizeof(map));
		for(i=1;i<=r;i++)
				scanf("%s",&smap[i]);
			x=1;y=start-1;
			flag=1;
			total=0;
			while(flag){
				switch(smap[x][y]){
				case 'E':y++;
					break;
				case 'W':y--;
					break;
				case 'N':x--;
					break;
				case 'S':x++;
					break;
				}
				if(x>=1&&x<=r&&y>=0&&y<=c-1){
					if(!map[x][y]){
						total++;
						map[x][y]=total;
						}
					else{
												printf("%d step(s) before a loop of %d step(s)\n",map[x][y],total-map[x][y]+1);
						flag=0;
					}
				}
				else {
					printf("%d step(s) to exit\n",total+1);
					flag=0;
				}
			}
	}
	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