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

We need 1000000 space to save the input
Posted by Lph 8 Sep 2016 09:36
#include<math.h>
#include<iostream>
#include <iomanip>
using namespace std;
#include<cstring>
#include<stdlib.h>

template <class T> class lstack
{
public:
    lstack(int k)
    {
        blink=(T*)malloc(sizeof(T)*k);
        len=k;
        cnt=0;
    }
    ~lstack()
    {
        free(blink);
    }
    T* pop(T* ptr)
    {
        if(cnt==0)
            return NULL;
        cnt--;
        memcpy(ptr,(blink+cnt),sizeof(T));
        return ptr;
    }
    bool push(const T* ptr)
    {
        if(cnt==len)
            return false;
        memcpy((blink+cnt),ptr,sizeof(T));
        cnt++;
        return true;
    }
private:
    T* blink;
    int len,cnt;
};


int main()
{
    lstack<double> s(1000000);//When I use 100000,it's wrong....
    double a;
    while(cin>>a)
    {
        s.push(&a);
    }
    while(s.pop(&a)!=NULL)
    {
        cout<<setprecision(4) <<fixed<<sqrt(a)<<endl;
    }
    return 0;
}
Re: We need 1000000 space to save the input
Posted by ToadMonster 8 Sep 2016 14:48
1) We don't need. By task description max input size is 256Kb.
It means max numbers count is 128K.

2) google STL containers - vector, queue, deque, stack.