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 CoyBaby at 2015-04-21 22:47:40 on Problem 1573
#include<iostream>
using namespace std;
#include<string>
#include<cstring>
int main()
{
    int m,n,t,bit[11][11],i,j,ans;
    string data[11];
    while(cin>>m>>n>>t&&m&&n&&t)
    {
        memset(bit,0,sizeof(bit));
        ans=0;
        for(int k=1;k<=m;k++)
            cin>>data[k];
        i=1;j=t-1;
        while(1)
        {
            ++ans;
            if(bit[i][j])
                {
                cout<<bit[i][j]-1<<" step(s) before a loop of "<<ans-bit[i][j]<<" step(s)"<<endl;
                break;
                }
            else
                bit[i][j]=ans;//记录步骤数
            switch(data[i][j])
            {
                case 'N':i--;break;
                case 'S':i++;break;
                case 'W':j--;break;
                case 'E':j++;break;
            }
            if(i<1||j<0||i>m||j>=n)
            {
                cout<<ans<<" step(s) to exit"<<endl;
                break;
            }
        }
    }
    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