编程介的小学生 2020-01-17 21:53 采纳率: 20.5%
浏览 125

Calculator 计算器的问题

Problem Description
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.

Input
The first line of input contains T (0 < T <= 100) the number of polynomials, each test cases consists of two lines, the first line contains an integer (-1000 <= X <= 1000), the value for the variable X for which the polynomial is evaluated.
The second line contains a polynomial P with integer coefficients. P is a sum of terms of the form CX^E , where the coefficient C and the exponent E satisfy the following conditions:
1. E is an integer satisfying (0 <= E <= 30). If E is 0, then CX^E is expressed as C. If E is 1, then CX^E is expressed as CX, unless C is 1 or -1. In those instances, CX^E is expressed as X or -X.
2. C is an integer. If C is 1 or -1 and E is not 0 or 1, then the CX^E will appear as X^E or -X^E.
3. Only non-negative C values that are not part of the first term in the polynomial are preceded by +.
4. Exponents in consecutive terms are strictly decreasing.
5. C fits in a 32-bit signed integer.

Output
For each test case, print the value of polynomial evaluation. The result will fit in a 32-bit signed integer. Follow the output format below.

Sample Input
2
-2
2X^2-5X+7
2
-3X^12+X

Sample Output
Case #1: 25
Case #2: -12286

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料