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 dad_mom at 2010-08-10 14:17:48 on Problem 1111 and last updated at 2010-08-10 14:19:07
#include<iostream>
#include<string>
using namespace std;
char cha[21][21];
int visit[21][21];
int col,row;
int mark(int i,int j)
{
	if(i>0&&i<=row&&j>0&&j<=col&&cha[i][j]=='X'&&visit[i][j]==0)
	{
		
		visit[i][j]=1;
		mark(i-1,j-1);
		mark(i-1,j);
		mark(i-1,j+1);
		mark(i+1,j-1);
		mark(i+1,j);
		mark(i+1,j+1);
		mark(i,j-1);
		mark(i,j+1);
	}
	return 0;
}
int main()
{
    int i,row1,col1,t,j;
	while(cin>>row>>col>>row1>>col1)
	{
		
		if(row==0&&col==0&&row1==0&&col1==0) break;
        memset(cha,'0',sizeof(cha));//就是这个函数。。哎!!
		for(i=1;i<=row;i++)
		{
			for(j=1;j<=col;j++)
			{
			cin>>cha[i][j];
			}
		}
		memset(visit,0,sizeof(visit));
		mark(row1,col1);
		t=0;
        for(i=1;i<=row;i++)
		{
			for(j=1;j<=col;j++)
			{ 
				if(visit[i][j]==1)
				{
				
						if(cha[i-1][j]!='X')
					{
						t++;
					}
					if(cha[i+1][j]!='X')
					{
						t++;
					}
					if(cha[i][j-1]!='X')
					{
						t++;
					}
					if(cha[i][j+1]!='X')
					{
						t++;
					}
				}
			}
		}
		cout<<t<<endl;
	}
}

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