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

Anyone can shed some light for me[wrong answer:( ]
Posted by AlainDelon 5 Oct 2007 12:58

===========================
#include <stdio.h>
#include <math.h>
#include <iostream>

#define MAXNUM 32768

using namespace std;


void main()
{
    int i = 0;

    double dList[MAXNUM];
    double dCur = 0.0;


    while(cin>>dCur)
    {
        if(dCur >=0.0 )
        {
        dList[i] = sqrt(dCur);
        ++i;
        }

        if(i>= MAXNUM) break;
    }


    while(i>0)
    {
        printf("\n%.4f", dList[i-1]);
        --i;
    }

}
==============================
Re: Anyone can shed some light for me[wrong answer:( ]
Posted by AlainDelon 5 Oct 2007 13:42
well, the original problem was resolved. I used malloc to allocate larger array instead of using static array. Here is a new question, why do I get "compilation error" through the code below?(both via c or c++ type)

>>>>>>>>>>>>>>>>>>>>>>>>
#include <stdio.h>
#include <math.h>
#include <malloc.h>



#define MAXNUM 800000


void main()
{
    int i = 0;

    double *dList = NULL;
    double dCur = 0.0;

    dList = (double*)malloc(MAXNUM * sizeof(double));



    while(scanf("%lf", &dCur) != EOF)
    {
        if(dCur >=0.0 )
        {
        dList[i] = sqrt(dCur);
        ++i;
        }


    }


    while(i>0)
    {
        printf("%.4f\n", dList[i-1]);
        --i;
    }

    free(dList);

}

<<<<<<<<<<<<<<<
Re: Anyone can shed some light for me[wrong answer:( ]
Posted by Une 9 Oct 2007 06:39


Edited by author 09.10.2007 06:41