|
|
вернуться в форумWe need 1000000 space to save the input Послано Lph 8 сен 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 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. |
|
|