|  | 
|  | 
| back to board | Accepted Solution C++ / Any ideas on how to optimize it? Posted by Haji  24 Jan 2013 13:19#include <stack>#include <cmath>
 
 using namespace std;
 
 int main()
 {
 double n;
 stack<double> numbers;
 
 while (scanf("%lf", &n) != EOF)    numbers.push(n);
 while (!numbers.empty())
 {
 printf ( "%.4f\n", sqrt( double(numbers.top()) ) );
 numbers.pop();
 }
 
 return 0;
 }
Re: Accepted Solution C++ / Any ideas on how to optimize it? Posted by cures  18 May 2014 11:40Yep!Read and parse input manually, scanf is expensive, %lf is even more expensive. As a bonus, you would not have to store read doubles. What surprised me is that printf is even much more expensive, so if you can create text representation of a double in given format - you are welcome!
 I have just got 0.031s execution time, what is yours?
 | 
 | 
|