全部RE
查看原帖
全部RE
540872
z_yk楼主2022/8/27 10:41

各位大佬帮忙看一下错在哪里,谢谢

#include<iostream>
#include<stack>

using namespace std;

stack<char>st;

int main()
{
	string a;
	long long ans = 0;
	cin >> a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > '0' && a[i] < '9')
		{
			st.push(a[i]);
		}
		else if (a[i] = '+')
		{
			int temp1, temp2;
			temp1 = st.top() - '0';
			st.pop();
			temp2 = st.top() - '0';
			st.pop();
			ans += temp1 + temp2;
		}
		else if (a[i] = '-')
		{
			int temp1, temp2;
			temp1 = st.top() - '0';
			st.pop();
			temp2 = st.top() - '0';
			st.pop();
			ans += temp2 - temp1;
		}
		else if (a[i] = '*')
		{
			int temp1, temp2;
			temp1 = st.top() - '0';
			st.pop();
			temp2 = st.top() - '0';
			st.pop();
			ans += temp2 * temp1;
		}
		else if (a[i] = '/')
		{
			int temp1, temp2;
			temp1 = st.top() - '0';
			st.pop();
			temp2 = st.top() - '0';
			st.pop();
			ans += temp2 / temp1;
		}
        else continue; 
	}
	cout << ans;
	return 0;
}
2022/8/27 10:41
加载中...