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

二个getchar废了我半个小时,贴代码

Posted by qiuzhenqiu at 2010-08-05 11:09:26
#include <stdio.h>
#include<string.h>
char a[25][25];
int sum;
int r,c;
void fun(int i,int j);
  int main(int argc, char *argv[])
  {
    int i,j,d,b,temp;
    char t;
    while(1)
    {
        memset(a,0,sizeof(a));
        sum=0;
          scanf("%d%d",&c,&r);
          getchar();
         if(c==0&&r==0)
         break;
         for(i=1;i<=r;i++)
         {
               for(j=1;j<=c;j++)
              {
                  scanf("%c",&t);
                 if(t=='.')
                 a[i][j]=1;
                 else if(t=='@')
                 {d=i;b=j;a[i][j]=1;}
                  else
                 a[i][j]=0;
               }
               getchar();
         }

          fun(d,b);
          printf("%d\n",sum);
    }
    return 0;
  }
void fun(int i,int j)
{
    if(a[i][j]==1)
    {
        a[i][j]=0;
        sum++;
        fun(i-1,j);
        fun(i+1,j);
        fun(i,j-1);
        fun(i,j+1);
    }
    
}

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