m0_56544118
2021-05-01 11:21
采纳率: 100%
浏览 71

c语言更改数组,大佬帮下下

求助!!! int a[10][10]= {0,1,0,1,0,0,0,0,0,0, 1,0,0,0,0,0,1,1,1,1, 0,0,0,0,1,1,0,0,0,0, 1,0,0,0,0,0,1,1,1,1, 0,0,1,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0,0, 0,1,0,1,0,0,0,0,0,0, 0,1,0,1,0,0,0,0,0,0, 0,1,0,1,0,0,0,0,0,1, 0,1,0,1,0,0,0,0,1,0}; int f[4]={1,3,2,8}; for(int i=0;i<4;i++) for(int j=i;j<4;j++) 便利在a中得到如下坐标 a[1][3],a[1][2],a[1][8],a[3][2],a[3][8],a[2][8] 原来为1则为1,原来为0则为0。其他均变为0。 也就是得到a数组中,只有a[1][8],a[3][8]为1。其余均为0的数组。 用c写。 大佬帮一下啊,谢谢。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • CSDN专家-三岁丫 2021-05-01 13:25
    已采纳
    int main()
    {
        int a[10][10]= {{0,1,0,1,0,0,0,0,0,0},
                        {1,0,0,0,0,0,1,1,1,1},
                        {0,0,0,0,1,1,0,0,0,0},
                        {1,0,0,0,0,0,1,1,1,1},
                        {0,0,1,0,0,0,0,0,0,0},
                        {0,0,1,0,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,1},
                        {0,1,0,1,0,0,0,0,1,0}};
        int f[] = {1, 3, 2, 8};
        int p = 4;
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                int flag = 1;
                for (int k = 0; k < p; ++k) {
                    for (int l = k + 1; l < p; ++l) {
                        if (f[k] == i && f[l] == j) {
                            flag = 0;
                            break;
                        }
                    }
                    if (!flag)
                        break;
                }
                if (flag)
                    a[i][j] = 0;
                printf("%d ", a[i][j]);
            }
            printf("\n");
        }
    
        return 0;
    }

    不好意思,之前一直没有仔细看题。

    已采纳该答案
    评论
    解决 1 无用
    打赏 举报
  • CSDN专家-三岁丫 2021-05-01 11:24

    你的难点是啥呢,不会遍历二维数组吗?

    评论
    解决 无用
    打赏 举报
  • CSDN专家-三岁丫 2021-05-01 11:36
    int main()
    {
        int a[10][10]= {{0,1,0,1,0,0,0,0,0,0},
                        {1,0,0,0,0,0,1,1,1,1},
                        {0,0,0,0,1,1,0,0,0,0},
                        {1,0,0,0,0,0,1,1,1,1},
                        {0,0,1,0,0,0,0,0,0,0},
                        {0,0,1,0,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,1},
                        {0,1,0,1,0,0,0,0,1,0}};
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                if ((i == 1 && j == 3) || (i == 1 && j == 2) || (i == 1 && j == 8) || (i == 3 && j == 2) || (i == 3 && j == 8) || (i == 2 && j == 8)) {
                    continue;
                }
                a[i][j] = 0;
            }
        }
    
        return 0;
    }

    你还是直接看我的吧,你的思路有问题

    评论
    解决 无用
    打赏 举报
  • CSDN专家-三岁丫 2021-05-01 12:11
    int main()
    {
        int a[10][10]= {{0,1,0,1,0,0,0,0,0,0},
                        {1,0,0,0,0,0,1,1,1,1},
                        {0,0,0,0,1,1,0,0,0,0},
                        {1,0,0,0,0,0,1,1,1,1},
                        {0,0,1,0,0,0,0,0,0,0},
                        {0,0,1,0,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,0},
                        {0,1,0,1,0,0,0,0,0,1},
                        {0,1,0,1,0,0,0,0,1,0}};
        int p[5][2] = {{1,3}, {1,2}, {1,8}, {3,2}, {3,8}, {2,8}};
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                int flag = 0;
                for (int k = 0; k < 5; ++k) {
                    if (i == p[k][0] && j == p[k][1])
                        flag = 1;
                }
                if (flag)
                    a[i][j] = 0;
            }
        }
    
        return 0;
    }
    评论
    解决 无用
    打赏 举报
  • C和C++技术博客 2021-05-03 16:50

    C和C++算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html

    评论
    解决 无用
    打赏 举报
  • 有问必答小助手 2021-05-04 22:10

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    评论
    解决 无用
    打赏 举报
  • 有问必答小助手 2021-05-06 16:12

    非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!

    速戳参与调研>>>https://t.csdnimg.cn/Kf0y

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题