#46162: 今天告白成功!!! 星星同意嫁給我!!!


1121226@stu.wghs.tp.edu.tw (Arthur✨EC)

學校 : 臺北市私立薇閣高級中學
編號 : 252772
來源 : [60.248.154.139]
最後登入時間 :
2025-08-21 12:59:45

#include <bits/stdc++.h>
using namespace std;
// 定義三個函數的計算
long long int f(int x) {
    return 2*x-3;
}
long long int g(int x, int y) {
    return 2*x+y-7;
}
long long int h(int x, int y, int z) {
    return 3*x-2*y+z;
}
int main(){
    string s;
    vector<string> a;
    while (cin>>s){
        a.push_back(s);
    }
    reverse(a.begin(),a.end());
    stack<long long int> st;
    for (int i=0;i<a.size();i++){
        if (a[i]=="f"){
            long long int arg=st.top();
            st.pop();
            st.push(f(arg));
        }
        else if (a[i]=="g"){
            long long int arg1=st.top();
            st.pop();
            long long int arg2=st.top();
            st.pop();
            st.push(g(arg1, arg2));
        }
        else if (a[i]=="h"){
            long long int arg1=st.top();
            st.pop();
            long long int arg2=st.top();
            st.pop();
            long long int arg3=st.top();
            st.pop();
            st.push(h(arg1,arg2,arg3));
        }
        else{
            // 數字
            st.push(stoll(a[i]));
        }
    }
    cout<<st.top()<<endl;
    return 0;
}