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

1001 Why wrong answer?
Posted by Alexandra 27 Jul 2011 01:10
#include <stdio.h>
#include <math.h>

int c;
float string[1024];
int i=0,b=0;

void main(){
    while((scanf("%d",&c)) != EOF){
        string[b]=c;
        b++;
        }
    for (i=b-1;i>-1;i--)printf("%f \n",sqrt(string[i]));
}
Re: 1001 Why wrong answer?
Posted by morbidel 27 Jul 2011 14:18
Try double instead of float because the numbers can be as large as 10^18.
Also the 1024 limit of the array is small, try 1000000.
Re: 1001 Why wrong answer?
Posted by Alexandra 27 Jul 2011 23:49
I try, but I have got the same result
Re: 1001 Why wrong answer?
Posted by daftcoder [Yaroslavl SU] 28 Jul 2011 11:14
1) Sure float is not enough, use double.
2) Also the numbers in input can be about 10^18, and int is also not enough! Use long long.
3) Also there is about 256*1024 = 262 144 bytes in input, so there could be about 131 072 numbers!

I edited your code a little and got AC.
Re: 1001 Why wrong answer?
Posted by Alexandra 28 Jul 2011 16:32
#include <stdio.h>
#include <math.h>

long long c;
double string[1000000];
long i=0, b=0;

void main(){
    while((scanf("%d",&c)) != EOF){
        string[b]=c;
        b++;
        }
    for (i=b-1;i>-1;i--)printf("%f \n",sqrt(string[i]));
}

?
Re: 1001 Why wrong answer?
Posted by daftcoder [Yaroslavl SU] 28 Jul 2011 17:03
Now problem with scanf/printf parameters
 - for long long "lld" or "I64d";
 - for double "lf"

So correct to scanf("%lld"... and printf("%lf... and get AC =)
Re: 1001 Why wrong answer?
Posted by Alexandra 28 Jul 2011 17:10
Thank you :)