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

Wrong answer(please help with input array)
Posted by Dmitriy 8 Sep 2011 13:50
Code: C/C++
#include <iostream>
#include <math.h>
#include <stdio.h>


int main() {
    const int N=10000;
    double a[N];
    long count=0,i;

while (std::cin>>a[i]) {
    std::cin>>a[i];
    count++;}
printf("\n");
for(i=count-1;i>=0;i--)
    printf("%25.4lf\n",sqrt(a[i]));
    return 0; }
Question:How to insert an array to provide input before the end of the border
Please help, I`am beginner=( Thanks.
Re: Wrong answer(please help with input array)
Posted by morbidel 8 Sep 2011 20:29
1. N can be maximum 131072 so adjust N accordingly.
2. Move double A[N] outside the main function as it exceeds the stack memory.
3. Initialize i and increase it after reading a[i].
4. You have two statements of cin >> a[i]. Delete the second one.
5. Eliminate %25.4 from the printing, leave just %.4

You'll get AC.

Edited by author 08.09.2011 20:29
Re: Wrong answer(please help with input array)
Posted by MaximG. 25 Oct 2011 20:10
could you tell me , why 131072?
Re: Wrong answer(please help with input array)
Posted by morbidel 25 Oct 2011 20:42
The statement say that the input size does not exceed 256KB that means 262144 bytes. The "worst" input should be "d d d" etc (one digit number, one space) so there can be maximum of INPUT/2 numbers.
Re: Wrong answer(please help with input array)
Posted by MaximG. 25 Oct 2011 22:19
2 morbidel: thank you very much!