2x+2y+4xy simplify("2xy-yx") =>xy simplify("xzy+zby") =>byz+xyz simplify(&qu">
我考虑用正则去做,正则写半天没写出来,求高人解救测试规则如下:
simplify("3x+y-x+2y+5xy-y-xy") => 2x+2y+4xy simplify("2xy-yx") =>xy simplify("xzy+zby") =>byz+xyz simplify("xzy+zby") =>byz+xyz simplify("y-x")=>-x+y
只用正则是做不到的
用正则和Map可以实现,累加变量的系数存到Map里,最后按变量名排序,手机不好打字