int main(void) { char shijie[HS][LS]; du_cssj(shijie,sizeof(shijie)/sizeof(shijie[0])); do { xs_shijie(shijie,sizeof(shijie)/sizeof(shijie[0])); js_weilai(shijie,sizeof(shijie)/sizeof(shijie[0])); } while(sf_jx()); system(“pause”); return 0; } int js_ljsm(const int gzh,const int gzl,char sj[][LS],const int sjhs) { int sm=0; int h,l; for(h=gzh-1;h<=gzh+1;h++) { for(l=gzl-1;l<=gzl+1;l++) { if(h<0||h>=sjhs) continue; if(l<0||l>sizeof(sj[0])/sizeof(sj[0][0])) continue; if(sj[h][l]==XB) sm++; } } return sm; } void cb_shijie(char from[][LS],char to[][LS],const int hs) { int h,l; for(h=0;h<hs;h++) for(l=0;l<sizeof(from[0])/sizeof(from[0][0]);l++) to[h][l]=from[h][l]; return ; } void js_weilai(char sj[][LS],const int hs) { char dpsj[HS][LS]; cb_shijie(sj,dpsj,hs); { int h,l; for(h=0;h<hs;h++) {for(l=0;l<sizeof(sj[0])/sizeof(sj[0][0]);l++) { int ljsm; ljsm=js_ljsm(h,l,dpsj,sizeof(dpsj)/sizeof(dpsj[0])); switch (ljsm) {case HOU1:break; case HOU2:sj[h][l]=XB;break; default:sj[h][l]=KB;break; }

      }
    }
 }
 return ;

} void xs_shijie(char sj[][LS],const int hs) { int h,l; system(“CLS”); for(h=0;h<hs;h++) {for(l=0;l<sizeof(sj[0])/sizeof(sj[0][0]);l++) { putchar(sj[h][l]);
} putchar(’\n’); } putchar(’\n’); putchar(’\n’); return ; } void du_cssj(char sj[][LS],const int hs) { int h,l; freopen(“input.txt”,“r”,stdin); for(h=0;h<hs;h++) {for(l=0;l<sizeof(sj[0])/sizeof(sj[0][0]);l++) { char c; scanf("%c",&c); #define SBBZ ‘*’ sj[h][l]=(c==SBBZ)?XB:KB; #undef SBBZ } getchar(); } freopen(“CON”,“r”,stdin); return; } int sf_jx(void) { printf(“continue?”); return (getchar()==’\n’)?1:0; }


输入文件 input.txt(大家可以自己写,*代表细胞位置)

1**4567890123456789012345*78**123456789012345*78**1234567890
12345*78**123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*45678901234567890*2345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456*89012345*78**1234567890
12*45678901234567890*2345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890
12*4567890123456789012345*78**123456789012345*78**1234567890

</div>