全红求助

B2144 阿克曼(Ackermann)函数

@[fty123456___](/user/993688) ```cpp #include<iostream> using namespace std; int a,b; int x(int a,int b){ if(a==0) return b+1; else if(a>0&&b==0) return x(a-1,1); else return x(a-1,x(a,b-1)); } int main(){ cin>>a>>b; cout<<x(a,b); return 0; } ```
by ZTT1014 @ 2024-03-20 22:18:23


你的b没输入上值,还有第5行不应该是b++。
by ZTT1014 @ 2024-03-20 22:22:59


@[ZTT1014](/user/1047386) 谢谢大佬
by fty123456___ @ 2024-03-23 14:26:38


```cpp #include<bits/stdc++.h> using namespace std; int Ackermann(int m,int n) { if(m == 0) { return n + 1; } else if(m > 0 && n == 0) { return Ackermann(m - 1 , 1); } if(m > 0 && n > 0) { return Ackermann(m - 1, Ackermann(m , n - 1)); } } int main() { int m , n; cin >> m >> n; cout << Ackermann(m , n) << endl; return 0; }
by Jason101 @ 2024-09-17 18:45:04


|