# UVa 10696 ### 題目連結:[UVa 10696](https://domen111.github.io/UVa-Easy-Viewer/?10696) ### 題述:McCarthy是一個有名的資訊專家。他定義了一個遞迴的函數叫做``f91``。它輸入一個正整數N並且依據以下的規則傳回一個正整數: ##### ``如果 N <= 100,那麼f91(N) = f91(f91(N+11))`` ##### ``如果 N >= 101,那麼f91(N) = N-10`` #### 請你寫一個程式來計算f91 #### 每組測試資料一列。含有1個正整數N(N<=1000000)。輸入最多有250000組測試資料。 #### 若 N=0 代表輸入結束。 ### c++ code: ```cpp= #include<iostream> using namespace std; int f91( int n){ if (n >= 101){ return n-10 ; } else if ( n <= 100 ) { return f91(f91(n+11)); } } int main() { int q ; while (cin>>q) { if (q == 0 ) { break; } else{ cout << "f91("<< q << ") = " << f91(q) << endl ; } } return 0; } ``` :::success **``sample input``** 500 91 0 ::: :::success **``sample output``** f91(500) = 490 f91(91) = 91 ::: #### [返回首頁](https://hackmd.io/@fkleofk/APCS#10696) ###### tags: `APCS選修` `C++` `UVa`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up