ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
back to board

Discussion of Problem 1001. Reverse Root

wrong answer C++
Posted by Igor 20 Mar 2023 12:40
I want to solve the problem using a dynamic array. But the compiler outputs this: HEAP CORRUPTION DETECTED: after Normal block (#150) at 0x000001EEFBCDB420.
CRT detected that the application wronte to memory after end of heap buffer.

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void main()
    int size = 0, i = 0;
        int* a = new int[size];
    unsigned int x;
    while (cin >> x)
        size += 1;
        for (; i < size;++i)
            a[i] = x;



    for (int i = size-1; i >= 0; --i)
        cout << fixed << setprecision(4) << sqrt(a[i]) << endl;
    delete[] a;

Edited by author 20.03.2023 12:40
Re: wrong answer C++
Posted by vzhanm 29 Apr 2024 11:23
Type int will overflow. Use unsigned long long instead.