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

Re:不解啊!!!wa了好几次

Posted by 3013216027 at 2014-07-22 09:14:18 on Problem 2386
In Reply To:不解啊!!!wa了好几次 Posted by:h452422845 at 2014-04-26 20:26:45
> #include <stdio.h>
> #include <string.h>
> char map[101][101];
> int n,m;
> //int move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
> void dfs(int x,int y)
> {
>     map[x][y]='.';
>    for(int dx=-1;dx<=1;dx++)
>     for(int dy=-1;dy<=1;dy++)
>    {
>        int nx=x+dx,ny=y+dy;
>        if(0<=nx&&nx<n&&0<=ny&&ny<m&&map[nx][ny]=='W')
>          dfs(nx,ny);
>    }
> }
> int main()
> {
>     int sum=0;
>     memset(map,0,sizeof(map));
>     scanf("%d%d",&n,&m);
>     for(int i=0;i<n;i++)
>         for(int j=0;j<m;j++)
>         scanf("%c",&map[i][j]);//为什么这样的输入不能ac
> //for(int i=0;i<n;i++)
>     //scanf("%s",&map[i]); //改成这样就ac了
>     for(int i=0;i<n;i++)
>     {
>         for(int j=0;j<m;j++)
>     {
>         if(map[i][j]=='W')
>            {
>                dfs(i,j);
>                sum++;
>            }
>     }
>     }
>     printf("%d\n",sum);
>     return 0;
> }
因为直接scanf("%c",&map[i][j]);可以读入回车符,
可以写成scanf(" %c", &map[i][j]);加空格就可以略过回车符鸟~~

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