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

Crash (access violation) on test 9
Posted by Kisenko Vova 23 Feb 2007 21:44
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
double a[100000];
long long n,i=0;
while (scanf("%I64d", &n) != EOF)
{
    a[i] = sqrt((double)n);
    i++;
}
for (int x=i-1;x>=0;x--)
    printf("%0.4f\n",a[x]);
return 0;
}

If I put range of array to 300000, i have "Crash (stack overflow)" on first test. What's wrong?
P.S Sorry for my bad English
Re: Crash (access violation) on test 9
Posted by Kit 23 Feb 2007 23:19
All variables inside functions is a dynamical variables, they always located in stack. By default stack is quite small. To avoid stack overflow move your array outside main function:
double a[1000000];
int main() {
}
You can also increase stack size, for that see help on C++.
P.S. Sorry for bad english too :)
Re: Crash (access violation) on test 9
Posted by Kisenko Vova 23 Feb 2007 23:45
Thank you very much