我有一个蒟蒻朋友,他托我前来求助
查看原帖
我有一个蒟蒻朋友,他托我前来求助
85587
Giggs楼主2020/7/16 16:37
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>
using namespace std;
string a;
stack<char> st;
int ans=0,sum=0;
int main()
{
	cin>>a;
	int l=a.size();
	for(int i=0;i<=l-1;i++)
	{
		if(a[i]=='@')
			break;
		if(a[i]!='.'&&a[i]>'0'&&a[i]<'9')
			 	{	
					int ab=a[i]-'0';
					ans=ans*10+ab;
				 }
			else if(a[i]=='+')
				{
					int jf1=st.top();
					st.pop();
					int jf2=st.top();
					st.pop();
					sum=jf1+jf2;
					st.push(sum);
					sum=0;
				}
				else if(a[i]=='-')
					{
						int gf1=st.top();
						st.pop();
						int gf2=st.top();
						st.pop();
						sum=gf2-gf1;
						st.push(sum);
						sum=0;
					}
					else if(a[i]=='*')
						{
							int cf1=st.top();
							st.pop();
							int cf2=st.top();
							st.pop();
							sum=cf1*cf2;
							st.push(sum);
							sum=0;
						}
						else if(a[i]=='/')
							{
								int chf1=st.top();
								st.pop();
								int chf2=st.top();
								st.pop();
								sum=chf2/chf1;
								st.push(sum);
								sum=0; 
							}	
							else
							{	
								st.push(ans);
								ans=0;
							}
	}
	cout<<sum;
	return 0;
}
2020/7/16 16:37
加载中...