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

Discussion of Problem 1001. Reverse Root

... Stack overflow... ? C++
Posted by Ingy 21 May 2014 14:51
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

int main ()
{
double number [100000];
int i=0;

while ( ! cin.eof())
{
cin >> number [i];
i++;
}

for( int j=i-1; j>=0; j--)
{
cout<< setprecision (4) << sqrt(number[j])<<endl;
}

return 0;
}

here's my program but I don't know what's wrong.. when i put the number of elements of the array to 140000 it says "stack overflow", when i put 10000 it says wrong answer.
Re: ... Stack overflow... ? C++
Posted by Smilodon_am [Obninsk INPE] 22 May 2014 14:58
All local variables are allocated in stack. Array "number"[] is local, because it is described in function "main". Standard size of stack is 1 MB, size of double variable is 8 bytes. So it isn't enough space to allocate all array with 140000 elements. You should increase stack size.
http://acm.timus.ru/help.aspx?topic=cpp

#pragma comment(linker, "/STACK:16777216")

Edited by author 22.05.2014 15:07