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 oceanwolf at 2009-06-07 21:46:50 on Problem 2386
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void solution(char str[][103],int i,int j)
{
     if(str[i][j]=='W')
     {
                       str[i][j]='.';
                       solution(str,i-1,j-1);
                       solution(str,i-1,j);
                       solution(str,i-1,j+1);
                       solution(str,i,j+1);
                       solution(str,i,j-1);
                       solution(str,i+1,j-1);
                       solution(str,i+1,j);
                       solution(str,i+1,j+1);
     }
     return ;
}
int main()
{
    int i,j,temp,m,n;
    char str[102][103],k;
    while(scanf("%d %d",&m,&n)!=EOF)
    {
           if(m==0) break;
           else
           {
                    temp=0;
                    for(i=0;i<m+2;i++)
                                     for(j=0;j<n+2;j++)
                                                       str[i][j]='.';
                    for(i=1;i<m+1;i++)
                    {
                                    
                                      scanf("%s",str[i]+1);
                                      str[i][n+1]='.';
                    }
                    
                    for(i=1;i<m+1;i++)
                    {
                                      for(j=1;j<n+1;j++)
                                      {
                                                        if(str[i][j]=='W')
                                                        {
                                                              temp++;
                                                              solution(str,i,j);
                                                        }
                                      }
                    }
                    printf("%d\n",temp);
           }
    }
       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