思路:利用lower_bound 搜尋60及格最低分,upper_bound + 反指標搜尋不及格最高分
實作:
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);//cin加速
cout.tie(0);
int n,input;
cin >> n;
vector <int> v;
while(n--){
cin>>input;
v.pb(input);
}
sort(all(v));//排序
for(int x:v){
cout << x << " ";
}
cout << endl;
auto pass_itr = lower_bound(all(v), 60);//查找60以上(含)最小值
auto fail_itr = upper_bound(rall(v), 60, greater<int>());//查找60以下最大值
cout << (fail_itr == v.rend() ? "best case" : to_string(*fail_itr)) << endl << (pass_itr == v.end() ? "worst case" : to_string(*pass_itr));//輸出結果
return 0;
}