zoukankan      html  css  js  c++  java
  • 关灯游戏,谁有简单的代码啊

    int light[4][4] = {
    {1, 1, 1, 1},
    {1, 1, 1, 1},
    {1, 1, 1, 1},
    {1, 1, 1, 1}
    };
    int x = 0, y = 0, sum = 0;
    for (int i = 0; i < 4; i ++) {
    for (int j = 0; j < 4; j ++) {
    printf("%d ", light[i][j]);
    sum += light[i][j];
    }
    printf("\n");
    }
    while (sum != 0){

    scanf("%d, %d", &x, &y);
    if (x > 4 || y > 4 || x <= 0 || y <= 0) {
    printf("请重新输入坐标:");
    scanf("%d, %d", &x, &y);
    }
    x --;
    y --;

    light[x][y] = (light[x][y] + 1) % 2;
    if (x > 0 && x < 3) {
    light[x - 1][y] = (light[x - 1][y] + 1) % 2;
    light[x + 1][y] = (light[x + 1][y] + 1) % 2;

    }
    if (x == 0) {
    light[x + 1][y] = (light[x + 1][y] + 1) % 2;
    }
    if (x == 3) {
    light[x - 1][y] = (light[x - 1][y] + 1) % 2;
    }
    if (y > 0 && y < 3) {
    light[x][y - 1] = (light[x][y - 1] + 1) % 2;
    light[x][y + 1] = (light[x][y + 1] + 1) % 2;
    }
    if (y == 0) {
    light[x][y + 1] = (light[x][y + 1] + 1) % 2;
    }
    if (y == 3) {
    light[x][y - 1] = (light[x][y - 1] + 1) % 2;
    }
    for (int i = 0; i < 4; i ++) {
    for (int j = 0; j < 4; j ++) {
    printf("%d ", light[i][j]);
    sum += light[i][j];
    }
    printf("\n");
    }
    }
    printf("恭喜您,终于玩完了!");

  • 相关阅读:
    AxMIMS系统开发环境搭建
    基于霍夫变换的点云分割方法
    微惯性导航系统
    “导航技术”学习笔记
    Kalman滤波学习
    Cell complex单元复形
    矩阵与欧拉角的转换
    CGAL4.10 / CGAL4.13编译
    [OpenCV]代码整理
    KinectFusion测试
  • 原文地址:https://www.cnblogs.com/Azazqing/p/3661415.html
Copyright © 2011-2022 走看看