Equation


题目描述:

E. Equation

Time Limit: 5000ms

Memory Limit: 65536KB
64-bit integer IO format: %lld Java class name: Main

Submit Status PID: 3688

Your task is to solve an equation of the form f(x) = 0 where f(x) is written in postfix notation with numbers, operations +, -, *, /, and at most one occurrence of a variable x.

For example, f(x) for an equation (4x + 2)⁄2 = 0 is written as:

4 X * 2 + 2 /

The solution for f(x) = 0 is x = −1⁄2.

Input

The input file consists of a single line with at most 30 tokens separated by spaces. Each token is either:
•a digit from 0 to 9;
•an operation +, -, *, or /;
•an uppercase letter X that denotes variable x.

The input file contains a correct representation of f(x) in postfix notation where token X occurs at most once. There is no division by a constant zero in this equation, that is, there always exists a value of x, such that f(x) can be evaluated without division by zero.

Output

Write to the output file:
•X = p/q if equation f(x) = 0 has a single solution that can be represented with a simple fraction p⁄q, where p and q are coprime integer numbers and q is positive.
•NONE if equation f(x) = 0 has no solution;
•MULTIPLE if equation f(x) = 0 has multiple solutions.

Sample Input

1 4 X * 2 + 2 /

2 2 2 *

3 0 2 X / *

Sample Output

1 X = -1/2

2 NONE

3 MULTIPLE

题解:

写一个表达式的结构体,然后就很简单了

重点:
代码:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值