c002. 10696 - f91

c002. 10696 - f91


解題思路 : 遞迴運用

程式碼

/*
c002. 10696 - f91
https://zerojudge.tw/ShowProblem?problemid=c002
skyblue
AC (2ms, 340KB)
*/

#include <bits/stdc++.h>
using namespace std;

int f91(int x){
    if(x >= 101) return x-10;
    else return f91(f91(x+11));
}

int main(){
    int x;

    while(scanf("%d", &x) == 1){
        if(x == 0) break;
        else printf("f91(%d) = %d\n", x,f91(x));
    }

    return 0;
}

留言

這個網誌中的熱門文章

a034.二進位轉換

a024.最大公因數(GCD)

d066.上學去吧!