---
# System prepended metadata

title: '題解 zerojudge f640: 函數運算式求值 APCS'
tags: [APCS, 遞迴, c++]

---

###### tags: `APCS` `c++` `遞迴`
# 題解 zerojudge f640: 函數運算式求值 APCS
```cpp=
#include<bits/stdc++.h>
using namespace std;

int v(){
    string s;
    int x,y,z;
    cin>>s;
    if(s=="f"){
        x=v();
        return 2*x-3;
    }
    else if(s=="g"){
        x=v();
        y=v();
        return 2*x+y-7;
    }
    else if(s=="h"){
        x=v();
        y=v();
        z=v();
        return  3*x-2*y+z;
    }
    else
        return stoi(s);

}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cout<<v();
}

```