社区讨论
RE求大佬帮调
P1449后缀表达式参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lpmkxnu9
- 此快照首次捕获于
- 2023/12/01 20:07 2 年前
- 此快照最后确认于
- 2023/12/01 21:49 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
stack<int> s;
int c,x,y,l;
char a[51];
int main(){
cin>>a;
for(int i=0;i<strlen(a);i++){
if(a[i]=='@'){cout<<s.top();return 0;}
if(a[i]=='+')x=s.top(),s.pop(),y=s.top(),s.pop(),s.push(x+y);
if(a[i]=='-')x=s.top(),s.pop(),y=s.top(),s.pop(),s.push(y-x);
if(a[i]=='*')x=s.top(),s.pop(),y=s.top(),s.pop(),s.push(x*y);
if(a[i]=='/')x=s.top(),s.pop(),y=s.top(),s.pop(),s.push(y/x);
if(a[i]!='+'&&a[i]!='-'&&a[i]!='*'&&a[i]!='/'){
while(a[i]!=' ')c=c*10+a[i++]-'0';
if(c>0&&a[i]=='.')s.push(c),c=0;
}
}
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...