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

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:40
Yep!
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?