qq_32742637 于 2016.03.26 16:27 提问

#define _CRT_SECURE_NO_WARNINGS //关闭安全检查
#include
#include
#define hs 3 //这能改行数
#define ls 3 //这能改列数
#define tiaojian1 2 //这里可改周围几个细胞时存活
#define tiaojian2 3 //这里可改周围几个细胞时繁殖
int world[hs][ls] = { 0 };
void shuru()
{
int i, j;
while (1)
{
scanf("%d%d", &i, &j);
if (i else if (i >= hs || j >= ls)
{
printf("输入数据超范围\n");
}
world[i][j] = 1; //1为生0为死
}
}
void shuchu()
{
int i, j, k = 0;
for (i = 0; i {
printf(" %d", i);
}
printf("\n");
printf(" ┌"); //第二行
for (i = 0; i {
printf("─┬");
}
printf("─┐\n");
for (i = 0; i {
printf("%d│", i);
for (j = 0; j {
if (world[i][j] == 1)
{
printf("●│");
k++;
}
else printf("○│");
}
printf("\n");
if (i == hs - 1) break;
printf(" ├");
for (j = 0; j {
printf("─┼");
}
printf("─┤\n");
}
printf(" └");
for (i = 0; i printf("─┴");
printf("─┘\n");
printf(" 现有%d个存活细胞\n", k);
}
int panduan(int h, int l)
{
int sum = 0, i, j;
for (i = h - 1; i {
for (j = l - 1; j {
if (i = hs)
continue;
if (j < 0 || j >= ls)
continue;
if (i == h&&j == l)
continue;
if (world[i][j] == 1)
sum += 1;
}
}
return sum;
}
void huanjing()
{
int b[hs][ls] = { 0 };
for (int h = 0; h < hs; h++)
{
for (int l = 0; l < ls; h++)
{
panduan(h, l);
b[h][l] = panduan(h, l);
}
}
for (int h = 0; h < hs; h++)
{
for (int l = 0; l < ls; h++)
{
if (b[h][l] == 3)
{
world[h][l] = 1;
continue;
}
else if (b[h][l] == 2)
{
continue;
}
else
{
world[h][l] = 0;
continue;
}
}
}
}
int main(void)
{
printf("生命游戏\n");
printf("默认世界大小3*3，世界大小及规则代码定义中可改\n");
printf("输入需要添加细胞的点的坐标，添加完成后输入一组负数坐标即可终止输入\n");
shuchu();
shuru();
shuchu();
system("pause");
while (1)
{
huanjing();
shuchu();
system("pause");
}

``````return 0;
``````

}

1个回答

caozhy      2016.03.26 22:52

b[h][l] = panduan(h, l);

qq_32742637 回复caozhy: 找到问题了。谢啦

qq_32742637 回复caozhy: 亲，没看懂啊，不知道怎么改啊，怎么会跳到20呢