題目描述
輸入一個整數n(n不大于1000),接下來分別為n個整數,請使用遞歸求取最大值。
輸入格式
第一行:正整數n。 第二行:n個整數。
輸出格式
輸出最大值
樣例
樣例輸入
復制2
1 2
樣例輸出
復制2
_____________________________________________________________________________
太難想了,感覺想出超時代碼已經很不錯了;
寫作不易,點個贊唄!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?
_____________________________________________________________________________
?
#include <bits/stdc++.h>
using namespace std;int f(int a){int x;cin>>x;if(a==1)return x;return max(x,f(a-1));
}
int n;
int main(){cin>>n; cout<<f(n);
}
?