rain487 2023-03-18 10:15 采纳率: 40%
浏览 135
已结题

代码改错:c/java同一思路

C/Java
想知道错在哪

img

1.c二维数组在vs上开到10010x10010(题目要求),在定义时报栈溢出错误,以前貌似是可以开到这么大的

img

2.当我缩小到100x100,仍不能完全通过,到底是错哪里呀??


#include<stdio.h>
int main() {
    int n, m, q;
    scanf_s("%d %d %d", &n, &m, &q);
    int a[100][100] = { 0 };
    for (int i = 0; i < q; i++) {
        int t,c;
        scanf_s("%d %d", &t, &c);
        if (t == 0) {
            for (int j = 0; j < m; j++) {
                a[c][j] = 1;
            }
        }
        if (t == 1) {
            for (int j = 0; j < n; j++) {
                a[j][c] = 1;
            }
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == 0) {
                cnt++;
            }
        }
    }
    printf("%d", cnt);
    return 0;
}

img

3.用java写,经常报“非零返回错误”,这段代码又有什么问题呀,同c的思路是一样的

import java.util.Scanner;
public class Main {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        int n,m,q;
        n=in.nextInt();
        m=in.nextInt();
        q=in.nextInt();
        int [][]arr=new int [n][m];
        for(int i=0;i<q;i++) {    //q行数据
            int t=in.nextInt();
            int c=in.nextInt();
            if(t==0) {
                for(int j=0;j<m;j++) {
                    arr[c][j]=1;
                }
            }
            if(t==1) {
                for(int j=0;j<n;j++) {
                    arr[j][c]=1;
                }
            }
        }
        int cnt=0;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(arr[i][j]==0) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}

运行结果:

img

  • 写回答

10条回答 默认 最新

  • 码诅 2023-03-18 10:34
    关注
    获得10.00元问题酬金

    题目是10的5次方,你最多才开10的4次方。把int a【100010】【100010】放在外面,就是开在堆区。其实这没必要开这么大数组来模拟,完全可以计算出来,参考下面的代码,下面的代码考虑的是行列不被多次选中的情况,你可以提交试试看

    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 3月26日
  • 创建了问题 3月18日

悬赏问题

  • ¥15 数据库原理及应用上机练习题
  • ¥30 征集Python提取PDF文字属性的代码
  • ¥15 如何联系真正的开发者而非公司
  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 (求远程解决)深信服vpn-2050这台设备如何配置才能成功联网?