From e7f861c77df0947b6eee758f1b7b974f1a076138 Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Wed, 6 May 2020 06:24:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=A6=E4=BD=9C=E6=8C=89=E4=B8=8B=200=20?= =?UTF-8?q?=E5=BE=8C=E6=80=8E=E9=BA=BC=E8=99=95=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidCalculator/Calculator.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) }