1 条题解
-
2
模仿课上后缀表达式的解法,然后根据题目的运算规则写出来即可
核心代码
for(int i=c.length()-1;i>=0;i--) { if(c[i]>='0'&&c[i]<='9') s.push(c[i]-'0'); else if(c[i]=='+'){ x=s.top(); s.pop(); y=s.top(); s.pop(); s.push(x+y); } else if(c[i]=='-'){ x=s.top(); s.pop(); y=s.top(); s.pop(); s.push(x-y); } else if(c[i]=='*'){ x=s.top(); s.pop(); y=s.top(); s.pop(); s.push(x*y); } else if(c[i]=='/'){ x=s.top(); s.pop(); y=s.top(); s.pop(); s.push(x/y); } }
- 1
信息
- ID
- 588
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- (无)
- 递交数
- 158
- 已通过
- 94
- 上传者