救济孩子吧!只过了一个用例,用了stack,本地用例能过
查看原帖
救济孩子吧!只过了一个用例,用了stack,本地用例能过
328313
syy981201楼主2022/3/16 17:28
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
const int N=1010;
int main()
{
	int now;
	char a;
	stack<int> s;
	while((a=getchar())!='@')
	{
		if(a>='0'&&a<='9') 
		{
			now*=10;
			now+=a-'0';
		}
		else if(a=='.')
		{
			s.push(now);
			now=0;
		}
		else if(a=='+')
		{
			int y=s.top();s.pop();
			int x=s.top();s.pop();
			int z=x+y;
			s.push(z);
		}
		else if(a=='-')
		{
			int y=s.top();s.pop();
			int x=s.top();s.pop();
			int z=x-y;
			s.push(z);
		}
		else if(a=='*')
		{
			int y=s.top();s.pop();
			int x=s.top();s.pop();
			int z=x*y;
			s.push(z);
		}
		else if(a=='/')
		{
			int y=s.top();s.pop();
			int x=s.top();s.pop();
			int z=x/y;
			s.push(z);
		}
	}
	cout<<s.top()<<endl;
	return 0;
}
2022/3/16 17:28
加载中...