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

Why wa #3??
Posted by efrenfuentes 22 Feb 2010 05:45
//============================================================================
// Name        : 1001. Reverse root
// Author      : Efrén Fuentes
// Version     : 1.00
// Copyright   : Efrén Fuentes. 2010
// Description : Imprimir las raices cuadradas en orden inverso
//============================================================================

#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

class Nodo {
public:
    long double valor;
    Nodo *anterior;
};

class Pila {
public:
    Nodo *tope;

    Pila() {
        tope = NULL;
    }

    void Push(long double valor) {
        Nodo *nuevo = new Nodo();
        nuevo->valor = valor;
        nuevo->anterior = tope;
        tope = nuevo;
    }

    void PushRaiz(long double valor) {
        Push(sqrt(valor));
    }

    long double Tope() {
        Nodo *ultimo = tope;
        long double valor = tope->valor;

        tope = ultimo->anterior;

        return valor;
    }
};

int main() {
    // declarar variables
    long double numero;
    Pila *pila = new Pila();

    // leer valores
    while(!cin.eof()) {
        cin >> numero;
        pila->PushRaiz(numero);
    }

    // el ultimo numero ingresa dos veces en la pila
    // hay que eliminarlo
    pila->Tope();

    // formatear la salida con 4 decimales
    cout << setiosflags(ios::fixed) << setprecision(4);

     // mostrar las raices
    while(pila->tope != NULL) {
        cout << pila->Tope() << endl;
    }

    return EXIT_SUCCESS;
}
Re: Why wa #3??
Posted by Sergey Lazarev (MSU Tashkent) 22 Feb 2010 23:11
Read FAQ: sizeof(long double) == sizeof(double) == 8 byte.
You should use "long long" for such big numbers as 10^18.