求助,只过了一个测试集
查看原帖
求助,只过了一个测试集
534258
waibiba卜楼主2021/7/6 18:45
#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
int main()
{
	int num;
	int n1,n2,n3;
	char ch;
	stack<int> s1;
	while((ch=getchar())!='@')
	{
		if(ch>='0'&&ch<='9')
		{
			num*=10;num+=ch-'0';continue;
		}
		else if(ch=='.')
		{
			s1.push(num);
			num=0;continue;
		}
		else 
		{
			n1=s1.top();
			s1.pop();
			n2=s1.top();
			s1.pop();
			if(ch=='+')
			n3=n1+n2;
			else if(ch=='-')
			n3=n2-n1;
			else if(ch=='*')
			n3=n1*n2;
			else if(ch=='/')
			n3=n2/n1;
			s1.push(n3);continue;
		}
	}
	cout<<s1.top();
	return 0;
 } 
2021/7/6 18:45
加载中...