From c9280090a6337649587bc763be01dd243a745d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=B8=B7=E9=BC=8E?= <13439470+he-weiding@user.noreply.gitee.com> Date: Sat, 23 Dec 2023 08:37:43 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=86=E6=B3=A2=E5=85=B0=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E6=B1=82=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 何帷鼎 <13439470+he-weiding@user.noreply.gitee.com> --- ...6\345\274\217\346\261\202\345\200\274.cpp" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "2209040008/chapter3/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" diff --git "a/2209040008/chapter3/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" "b/2209040008/chapter3/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" new file mode 100644 index 00000000..66af3779 --- /dev/null +++ "b/2209040008/chapter3/\351\200\206\346\263\242\345\205\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" @@ -0,0 +1,33 @@ +int evalRPN(char** tokens, int tokensSize) +{ + int n=tokensSize; + int a[n],top=-1; + for(int i=0;i1||(b[0]>='0'&&b[0]<='9')) + { + a[++top]=atoi(b);//将字符转换成int型整数 + } + else + { + switch(b[0]) + { + case '+': + a[top-1]=a[top-1]+a[top]; + break; + case '-': + a[top-1]=a[top-1]-a[top]; + break; + case '*': + a[top-1]=a[top-1]*a[top]; + break; + case '/': + a[top-1]=a[top-1]/a[top]; + break; + }//将栈顶的两个数按照运算符运算并将结果放回栈 + --top; + } + } + return a[top]; +} \ No newline at end of file -- Gitee From 6d942aa6222d85741eefd0c782e4e0bd93dce534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=B8=B7=E9=BC=8E?= <13439470+he-weiding@user.noreply.gitee.com> Date: Sat, 23 Dec 2023 09:34:03 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 何帷鼎 <13439470+he-weiding@user.noreply.gitee.com> --- ...4\350\256\241\347\256\227\345\231\250.cpp" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "2209040008/chapter3/\345\237\272\346\234\254\350\256\241\347\256\227\345\231\250.cpp" diff --git "a/2209040008/chapter3/\345\237\272\346\234\254\350\256\241\347\256\227\345\231\250.cpp" "b/2209040008/chapter3/\345\237\272\346\234\254\350\256\241\347\256\227\345\231\250.cpp" new file mode 100644 index 00000000..b0470018 --- /dev/null +++ "b/2209040008/chapter3/\345\237\272\346\234\254\350\256\241\347\256\227\345\231\250.cpp" @@ -0,0 +1,39 @@ +int calculate(char* s) +{ + int n=strlen(s); + int a[n], top=0; + char b='+'; + int num=0; + for (int i=0;i