哼哼啊啊啊啊啊 5TLE 5RE 救救 stack
查看原帖
哼哼啊啊啊啊啊 5TLE 5RE 救救 stack
583833
LubsWangKillThemAll楼主2022/5/30 18:27
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std;
stack<int>s;
int main()
{
	char c;
	int num = 0;
	while (1)
	{
		cin >> c;
		if (c >= '0' && c >= '9')
		{
			num = num * 10 + c - '0';
		}
		else if (c == '.')
		{
			s.push(num);
			num = 0;
		}
		else if (c == '+')
		{
			int num1 = s.top();
			s.pop();
			int num2 = s.top();
			s.pop();
			s.push(num1 + num2);
		}
		else if (c == '-')
		{
			int num1 = s.top();
			s.pop();
			int num2 = s.top();
			s.pop();
			s.push(num2 - num1);
		}
		else if (c == '*')
		{
			int num1 = s.top();
			s.pop();
			int num2 = s.top();
			s.pop();
			s.push(num1 * num2);
		}
		else if (c == '/')
		{
			int num1 = s.top();
			s.pop();
			int num2 = s.top();
			s.pop();
			s.push(num2 / num1);
		}
		else if (c == '@')
		{
			break;
		}
	}
	cout << s.top();
}
2022/5/30 18:27
加载中...