You will be given a preordered polynomial f(x). There will be Q queries, for each query x, please calculate the answer of f(x).
This is a partial judge problem, we have already implement a class Function to you. class Function has two functions:
You need to implement the following 6 class inheritted from Function:
Please paste the following code after the code you write, and don't forget to include "function.h"!
Function* Function::parse(stringstream &ss){
string s;
ss >> s;
if(s == "+" || s == "-" || s == "*" || s == "/"){
Function *a = parse(ss), *b = parse(ss);
Function *now = Arithmetic::create(a, s[0], b);
return now;
}else if(s[0] == 'x'){
Function *now = Variable::create(s);
return now;
}else if(s == "**"){
Function *a = parse(ss), *b = parse(ss);
Function *now = Polynomial::create(a, b);
return now;
}else if(s == "sin"){
Function *a = parse(ss);
Function *now = Sin::create(a);
return now;
}else if(s == "cos"){
Function *a = parse(ss);
Function *now = Cos::create(a);
return now;
}else{
Function *now = Constant::create(atoi(s.c_str()));
return now;
}
}
The first line contains a preordered polynomial f(x):
The second line contains an integer Q, means the number of queries.
The following Q lines are the queries, each line contains a number x.
The length of the first line won't exceed 1e6, and 1 <= Q <= 2e5.
Each constant and query is between [-100, 100]. It's guarantee that no overflow and divided by 0
For each x, please output the answer of f(x).