Redaksiya
The problem can be solved in two ways:
using a loop: read and print the value of on the fly;
implement as a function;
Read the input data until the end of the file.
Algorithm realization
Read the input data until the end of the file.
while(scanf("%lf",&x) == 1) {
For each test case compute and print the answer.
y = x * x * x + 2 * x * x - 3; printf("%.4lf\n",y); }
Algorithm realization — function
Define the f function.
double f(double x) { return x * x * x + 2 * x * x - 3; }
Read the input data until the end of the file. Compute and print the answer.
while(scanf("%lf",&x) == 1) printf("%.4lf\n",f(x));
Java realization
import java.util.*; public class Main { static double f(double x) { return x * x * x + 2 * x * x - 3; } public static void main(String[] args) { Scanner con = new Scanner(System.in); while(con.hasNext()) { double x = con.nextDouble(); System.out.println(f(x)); } con.close(); } }
Python realization — function
import sys
Define the f function.
def f(x): return x ** 3 + 2 * x * x – 3
Read the input data until the end of the file. Compute and print the answer.
for x in sys.stdin: x = float(x) print(f(x))
Python realization
import sys
Read the input data until the end of the file.
for x in sys.stdin:
For each test case compute and print the answer.
x = float(x) y = x ** 3 + 2 * x * x – 3 print(y)