eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Calculator

Calculator

The users feedback for your most beloved open-source operating system is gathered, and guess what the most required feature turned out to be? Yes it is finally what we all have been waiting for so long, extending the built-in calculator functionality! On of the suggested extensions is adding the capability of evaluating polynomials, and that’s what you are thrilled to participate with! In this problem you’re given a polynomial entered by the user in the calculator and are asked to evaluate it for a certain value. \InputFile The first line of input contains \textbf{T} (\textbf{0} < \textbf{T} ≤ \textbf{100}) the number of polynomials, each test cases consists of two lines, the first line contains an integer (\textbf{-1000} ≤ \textbf{X} ≤ \textbf{1000}), the value for the variable \textbf{X} for which the polynomial is evaluated. The second line contains a polynomial \textbf{P} with integer coefficients. \textbf{P} is a sum of terms of the form \textbf{CX^E} , where the coefficient \textbf{C} and the exponent \textbf{E} satisfy the following conditions: \begin{enumerate} \item \textbf{E} is an integer satisfying (\textbf{0} ≤ \textbf{E} ≤ \textbf{30}). If \textbf{E} is \textbf{0}, then \textbf{CX^E} is expressed as \textbf{C}. If \textbf{E} is \textbf{1}, then \textbf{CX^E} is expressed as \textbf{CX}, unless \textbf{C} is \textbf{1} or \textbf{-1}. In those instances, \textbf{CX^E} is expressed as \textbf{X} or \textbf{-X}. \item \textbf{C} is an integer. If \textbf{C} is \textbf{1} or \textbf{-1} and \textbf{E} is not \textbf{0} or \textbf{1}, then the \textbf{CX^E} will appear as \textbf{X^E} or \textbf{-X^E}. \item Only non-negative \textbf{C} values that are not part of the first term in the polynomial are preceded by \textbf{+}. \item Exponents in consecutive terms are strictly decreasing. \item \textbf{C} fits in a \textbf{32}-bit signed integer. \end{enumerate} \OutputFile For each test case, print the value of polynomial evaluation. The result will fit in a \textbf{32}-bit signed integer. Follow the output format below.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
2
-2
2X^2-5X+7
2
-3X^12+X
Выходные данные #1
Case #1: 25
Case #2: -12286
Источник The Third Lebanese Collegiate Programming Contest