#P2379. 整式的计算【数据有误】

    ID: 3169 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>模拟字符串数学洛谷原创

整式的计算【数据有误】

Background

Xiao Ming has started middle school. He keeps making mistakes in polynomial calculations, so he turned to you, a programming enthusiast, to design a program to help him.

Problem Description

Input several monomials or polynomials and compute the result.

Input Format

The expression includes +, -, *, and letters (only the 26 lowercase letters a to z). A monomial has no surrounding brackets; a polynomial is enclosed in ( ) or [ ]. It is guaranteed that, within each multiplicative factor, monomials come before polynomials. The length does not exceed 255.

Output Format

Output the result of the expression, with each factor arranged in lexicographic order.

(a+b)*(a+b+c)
a^2+2ab+ac+b^2+bc
(a+b)*(a+b+c)
a^2+2ab+ac+b^2+bc
(2a+b)*(2a-b)
4a^2-b^2
(a+b)*(a+b)*(a+b)
a^3+3a^2b+3ab^2+b^3
f*(a+b+d+z)+f^2
af+bf+df+fz+f^2
(a+b+2c)*(a+b-2c)-(a+b)*(a+b)
-4c^2

Hint

A simple problem.

Translated by ChatGPT 5