Solved LeetCode program · 547 of 1,000
#0770 · Basic Calculator IV
Original English source
Keep a shared token as empty text. Keep a shared parsed of 0. The expression is "e + 8 - a + 5". The tokens is split expression by " ". The constant is 0. The lettercoef is 0. The sign is 1. The last is the last position of tokens.
To read from spot (a whole number) with finish (a whole number). If spot is more than finish, return. The digit is the digit value of character spot of token. Set parsed to parsed times 10 plus digit. Read from spot plus 1 with finish.
For every spot from 0 to last.
Set token to item spot of tokens. The symbol is character 0 of token. If symbol is "+", set sign to 1. If symbol is "-", set sign to -1. Set parsed to 0. The finish is the last position of token. If symbol is between "0" and "9", read from 0 with finish. If symbol is between "0" and "9", set constant to constant plus sign times parsed. If symbol is "e", set constant to constant plus sign. If symbol is "a", set lettercoef to lettercoef plus sign.
If lettercoef is not 0.
The lead is format whole number lettercoef as text. Place "*a" into lead. Show lead.
Show format whole number constant as text.
Expected stdout
-1*a 14