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 12420210 at 2014-08-08 17:06:00 on Problem 1562
#include <iostream>
using namespace std;
char a[101][101];
int b[8][2]={1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};
void dfs(int x,int y)
{	a[x][y]='*';
	for(int k=0;k<8;k++)
		if(a[x+b[k][0]][y+b[k][1]]=='@')
		dfs(x+b[k][0],y+b[k][1]);
}
int main(int argc, char *argv[])
{
	int m,n;
	while(cin>>m>>n,m,n)
	{		
		int i,j,k,s=0;
		for(i=0;i<m;i++)
			for(j=0;j<n;j++)
				cin>>a[i][j];
		for(i=0;i<m;i++)
			for(j=0;j<n;j++)
				if(a[i][j]=='@'){s++;dfs(i,j);}
		cout<<s<<endl;
	}
	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