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

My problem:Crash (access violation) test6
Posted by siyuan503 16 Aug 2007 19:21
  Although I tried so many times,it showed Crash (access violation) test6.
  Who can tell me why,thanks.
  My mainly code:

main ()
{
 int n=0,i;
 double a, b[100];
 for(i=0;i<100;i++)
  b[i]=0;
 while(scanf("%lf",&a)!=EOF)
 {  b[n]=sqrt(a);  n++;}
 for(i=n-1;i>=0;i--)
  printf("%.4lf\n",b[i]);
}
Re: My problem:Crash (access violation) test6
Posted by CHIDEMYAN SERGEY 16 Aug 2007 19:45
Array of 100 elements doesn't enough.Create a dynamic array of 8000000 elements.Just do
double *b=new double[8000000];
Good luck!

Edited by author 16.08.2007 19:46

Edited by author 16.08.2007 19:47

Edited by author 16.08.2007 19:47

Edited by author 16.08.2007 19:50
Re: My problem:Crash (access violation) test6
Posted by siyuan503 16 Aug 2007 20:11
Sorry,my problem is "double *b=new double[8000000];"seems not available in C!
Re: My problem:Crash (access violation) test6
Posted by siyuan503 16 Aug 2007 20:16
if i write double[8000000]in C,it say overflow!
i will mad!
if this problem can't be achieved by C!
Re: My problem:Crash (access violation) test6
Posted by CHIDEMYAN SERGEY 17 Aug 2007 18:33
Ok.I'm don't well on C enough.Just do:
#include<stdio.h>
main ()
{
int n=0,i;
double a;
double *b=new double[8000000];
while(scanf("%lf",&a)!=EOF)
{ b[n]=sqrt(a); n++;}
for(i=n-1;i>=0;i--)
printf("%.4lf\n",b[i]);
return 0;
}
and you'll get AC on C++.

Edited by author 17.08.2007 18:33
Re: My problem:Crash (access violation) test6
Posted by siyuan503 24 Aug 2007 20:38
Thank you very much!
I will try it again.