1935接尾辞式(C++)


#include <iostream>
#include<stack>
#include<string>
using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	stack<double> mine;
	double arr[26];
	cout << fixed;
	cout.precision(2);
	for (int i = 0;i < N;i++) {
		cin >> arr[i];
	}


	for (int i = 0; i < S.length(); i++) {
		if ('A' <= S[i] && S[i] <= 'Z') {
			mine.push(arr[S[i]-65]);
		}
		else{
			double num2 = mine.top();
			mine.pop();
			double num1 = mine.top();
			mine.pop();
			if (S[i] == '+') {
				mine.push(num1 + num2);
			}
			else if (S[i] == '-') {
				mine.push(num1 - num2);
			}
			else if (S[i] == '*') {
				mine.push(num1 * num2);
			}
			else if (S[i] == '/') {
				mine.push(num1 / num2);
			}
		}
	}
	cout << mine.top();
	return 0;
}
スタックの説明を参照してください.
https://velog.io/@kimeunseo58/%EC%8A%A4%ED%83%9D
スタックソース:
https://velog.io/@kimeunseo58/10828%EC%8A%A4%ED%83%9DC