Why ia am getting SIGABRT err in coinflip program

#include

#include

using namespace std;

void startgame()

{

int I, N, Q;

cin >> I;

cin >> N;

cin >> Q;

vector<string> arr;

if (I == 1)

{

    arr = vector<string>(N, "H");

}

else

{

    arr = vector<string>(N, "T");

}

//log

/* cout << "array before change"

     << "\n";

for (int i = 0; i < arr.size(); i++)

{

    cout << arr[i] << "\t";

} */

//log end

int arrIndex = 0;

for (int j = N; j > 0; --j)

{

    if (j % 2 > 0)

    {

        if (arr[arrIndex] == "H")

        {

            arr.at(arrIndex) = "T";

        }

        else

        {

            arr.at(arrIndex) = "H";

        }

    }

    arrIndex = arrIndex + 1;

}

//log

/* cout << "\narray after change"

     << "\n";

for (int i = 0; i < arr.size(); i++)

{

    cout << arr[i] << "\t";

} */

//log end

int result = 0;

if (Q == 1)

{

    for (int i = 0; i < arr.size(); i++)

    {

        if (arr[i] == "H")

        {

            result = result + 1;

        }

    }

}

else

{

    for (int i = 0; i < arr.size(); i++)

    {

        if (arr[i] == "T")

        {

            result = result + 1;

        }

    }

}

cout << result << "\n";

}

void solve()

{

int G;

cin >> G;

while (G--)

{

    startgame();

}

}

int main()

{

int T;

cin >> T;

while (T--)

{

    solve();

}

}

I can’t remember why I think this, but I seem to recall the stated limits for N (N \le 10 at the time of writing) as being incorrect, and being more like N \le 10^9. If that’s the case, then:

vector<string>(N, "T");

etc probably won’t fit in RAM.

Edit:

This might be the reason I think this, but I’m sure I saw something suggestive of this more recently. Hmmm.

1 Like

Yes, you are right.
this program is getting executed correctly for small inputs but it cant handle large outputs , so i should use different logic for this problem i guess
btw thank you for suggestion

1 Like