Why can't my terminal read a lot of input and why is this not working on windows?

-3

I have a comlex school assignement but even though I've written a code, there are a few problems with it which I just can't understand. The program gets a number of days (N) and a number of places (M) and then reads that day's temperature in that place (H[i][j]) in a matrix. I got my program to work on the first example but when I copied in my second which should have been a 1000x1000 matrix the terminal stopped reading the files at a point and started beeping until I closed the window. I have to upload my code to a site which test automatically and I got 8 point out of 100, so if for some reason this can't read more than a few ints, that might be the reason.

I wrote this in Sublime Text on MacOS and builded in that, my mac can run it as described above, but I tried editing this on a windows computer as well (both in CodeBlocks and Geany) and every time it builds, but when I try to run it, it exits with -1073741571 (0xC00000FD). I found out this is for stack overflow, but don't know how to fix it or why it runs on my mac anyway.

#include <iostream>
#include <stdlib.h>

using namespace std;

const int maxN = 1000;
const int maxM = 1000;
const int maxK = 1000;

int main()
{
int N;
int M;
int H[maxN][maxM];

cin >> N >> M;

for (int i=0;i<N;++i)
{
    for (int j=0;j<M;++j)
    {
        cin >> H[i][j];
    }
}

int K;
int ezek[maxK];


int maxindexek[maxN];
int i;
int j;
maxindexek[0] = 0;
for (int i=0;i<N;i++)
{
    for (int j=0;j<M;j++)
    {
        if (H[i][j] > H[i][maxindexek[i]])
        {
            maxindexek[i] = j+1;
        }
    }
}

int lhmhn[maxM];
for (int y=0;y<M;y++)
{
    for (int x=0;x<N;x++)
    {
        if (maxindexek[x]==y+1)
        {
            lhmhn[y] = lhmhn[y] + 1;
        }
    }
}

int maxlhmhn = 0;
for (i=0;i<M;i++)
{
    if (lhmhn[i]>maxlhmhn)
    {
        maxlhmhn = lhmhn[i];
    }
}

K = 0;
for (i=0;i<M;i++)
{
    if (lhmhn[i]==maxlhmhn)
    {
        ezek[K] = i+1;
        K++;
    }
}

cout << K << " ";

for (i=0;i<K;i++)
{
    cout << ezek[i] << " ";
}

cout << endl;


return 0;
}

This code should give the (K) number of days when there was maximum of temperature in the most places then following these days. This isn't a pretty code, but I couldn't do better. Sorry, but I spent my day trying to fix this and I couldn't find an answer for any of my answers, I just can't get the problems. Hope you can help me.

c++
macos
asked on Stack Overflow Jan 3, 2019 by S. R. Bogi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0