[ create a new paste ] login | about

Link: http://codepad.org/UFLHo5LH    [ raw code | fork ]

C, pasted on Dec 5:
/* 上下左右につながる'#'で示される島の数を数える関数Funcを実装せよ。
 * 尚、gDtの内容は破壊してかまわないものとする。
 *  例1) 次の場合島の数は3
 *          ...##
 *          ..#..   <--- 上下左右につながっていないので1つと数える
 *          .....
 *          ..###
 *          ....#
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define N (5)
char gDt[N][N] ;

void    Disp();
int     Func();

int main(void) {
    int seed;
    int x,y,i;
    memset(gDt,'.',sizeof(gDt));
    printf("seed : %d \n",seed=time(NULL));
    srand(seed);
    for (i=0 ; i<2*N ; i++) {
        x = (rand()>>3)%N;
        y = (rand()>>3)%N;
        gDt[y][x] = '#';
    }
    Disp();
    printf("Ans : %d\n",Func());
    return 0;
}
void Disp() {
    int x,y;
    for (y=0 ; y<N ; y++) {
    for (x=0 ; x<N ; x++) {
        printf("%c",gDt[y][x]);
    } printf("\n"); }
}


Create a new paste based on this one


Comments: