diff --git a/AndroidCalculator/Calculator.swift b/AndroidCalculator/Calculator.swift index 41a0982..a9c6f6b 100644 --- a/AndroidCalculator/Calculator.swift +++ b/AndroidCalculator/Calculator.swift @@ -27,6 +27,16 @@ class Calculator { case "AC": // 清空到剩下 0 formula = ["0"] + + case "0": + if formula.last == "0" { + return + } else if ["+", "-", "×", "÷"].firstIndex(of: formula.last!) != nil { + formula.append(text) + } else { + formula.append(formula.popLast()! + text) + } + default: formula.append(text) }