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 shuangkouchengzhi at 2014-04-29 16:41:56 on Problem 2386
#include <iostream>
using namespace std;
void check(char**p,int,int);
int main()
{
    int N,M;
    cin>>M>>N;
    char**p=new char*[N];
    for (int i=0;i<N;i++) p[i]=new char[M];
    for (int j=0;j<N+2;j++)
    {
        p[0][j]='.';
        p[M+1][j]='.';
    }
    for (int i=1;i<M+1;i++)
    {
        p[i][0]='.';
        p[i][N+1]='.';
    }
    for (int i=1;i<=M;i++)
        for (int j=1;j<=N;j++)
            cin>>p[i][j];
    int counter=0;
    for(int i=1;i<=M;i++)
        for(int j=1;j<=N;j++)
            if(p[i][j]=='W')
            {
                counter++;
                p[i][j]=1;
                check(p,i,j);
            }
    cout<<counter<<endl;
    for (int i=0;i<N;i++) delete[] p[i];
    delete[] p;
    return 0;

}

 void check(char**p,int hang,int lie)
{
    bool flag=true;
    while(flag)
    {
        flag=false;
        if (p[hang-1][lie+1]=='W')
        {
            flag=true;
            p[hang-1][lie+1]=1;
            check(p,hang-1,lie+1);
        }
        for(int i=hang;i<=hang+1;i++)
            for(int j=lie-1;j<=lie+1;j++)
            {
                if(p[i][j]=='W')
                {
                    flag=true;
                    p[i][j]=1;
                    check(p,i,j);
                }
            }
    }
    if(flag==false) return;

}


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