求助 WA 50
  • 板块学术版
  • 楼主Literally
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/10/7 17:10
  • 上次更新2023/10/27 08:17:22
查看原帖
求助 WA 50
638141
Literally楼主2022/10/7 17:10

题目

提交记录

代码:

#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
stack<int> m;
int main(){
	char temp;
	int temp1=0,shu1,shu2;
	while(cin>>temp && temp!='@'){
		if(temp>='0' && temp<='9'){
			temp1*=10;
			temp1+=(temp-'0');
		}else if(temp=='.'){
			m.push(temp1);
			temp1=0;
		}else if(temp=='+'){
			shu1=m.top();
			m.pop();
			shu2=m.top();
			m.pop();
			m.push(shu1+shu2);
		}else if(temp=='*'){
			shu1=m.top();
			m.pop();
			shu2=m.top();
			m.pop();
			m.push(shu1*shu2);
		}else if(temp=='-'){
			shu1=m.top();
			m.pop();
			shu2=m.top();
			m.pop();
			m.push(abs(shu1-shu2));
		}else if(temp=='/'){
			shu1=m.top();
			m.pop();
			shu2=m.top();
			m.pop();
			m.push(shu1/shu2);
		}
	}
	cout<<m.top();
}

我下载了第二个数据,自己手算是3,程序输出也是3,可答案是7,十分不解

2022/10/7 17:10
加载中...