AOJ.667 抢占白房子

抢占白房子

点我挑战题目

考察点

字符串

Time Mem Len Lang
14ms 444 KB 0.75 K GCC

题意分析

数据仅有一组,根据题目,左上角的一个格子为白色,与白色相邻的(无论是左右,还是上下)都是黑色,与黑色相邻的都是白色。F代表被占领,求被占领的白格子的数量是多少。
首先构造一个8*8的数组,元素可以分别为0或1,1代表白格子,0代表黑格子。然后读入字符,判断F所对应的格子是否为1,是的话计数器加一。

代码总览

/*
    Title:AOJ.667
    Author:pengwill
    Date:2016-12-15
*/
#include <stdio.h>
#include <stdlib.h>

int main()
{
    //freopen("in.txt","r",stdin);
    int a[8][8] ={{1,0,1,0,1,0,1,0},
                  {0,1,0,1,0,1,0,1},
                  {1,0,1,0,1,0,1,0},
                  {0,1,0,1,0,1,0,1},
                  {1,0,1,0,1,0,1,0},
                  {0,1,0,1,0,1,0,1},
                  {1,0,1,0,1,0,1,0},
                  {0,1,0,1,0,1,0,1},
                                    };
    char table[8][8];
    int i,j;
    for(i = 0;i<8;i++){
        scanf("%s",table[i]);
    }
    int cnt = 0;
    for(i = 0;i<8;i++){
        for(j = 0;j<8;j++){
            if(table[i][j] == 'F'&& a[i][j] == 1){
                cnt ++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}
posted @ 2016-12-15 20:31  pengwill  阅读(107)  评论(0编辑  收藏  举报