Remove redundant parentheses from an arithmetic expression

后端 未结 7 1266
陌清茗
陌清茗 2020-12-13 10:27

This is an interview question, for which I did not find any satisfactory answers on stackoverflow or outside. Problem statement:

Given an arithmetic

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 11:33

    I think that you are looking for kind of algorithm as seen in the following photo.

    This algorithm is "almost" ready, since a lot of bugs arise once the more complex it becomes, the more complicated it gets. The way I work on this thing, is 'build-and-write-code-on-the-fly', which means that for up to 4 parentheses, things are easy. But after the expression goes more complex, there are things that I cannot predict while writing down thoughts on paper. And there comes the compiler to tell me what to correct. It would not be a lie if I state that it is not me to have written the algorithm, but the (C#) compiler instead! So far, it took me 1400 lines. It is not that the commands were difficult to write. It was their arrangement that was a real puzzle. This program you are looking for, is characterized by a really high grade of complexity. Well, if you need any primary ideas, please let me know and I will reply. Thanx!

    Algorithm

提交回复
热议问题