---
# System prepended metadata

title: APCS 2016/03 各種c++題解放置區

---

# APCS 2016/03 各種c++題解放置區
## 第1題 成績指標
[試題卷網址](https://apcs.csie.ntnu.edu.tw/wp-content/uploads/2020/10/APCS-%E5%AF%A6%E4%BD%9C%E9%A1%8C-2016.03.05.pdf)
[zerojudge網址](https://zerojudge.tw/ShowProblem?problemid=b964)
:::spoiler 解法一：由小到大找，只紀錄第一個及格分數的idx，三種情境分別輸出
```cpp=
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    for(int i=0; i<n; i++){
        cout << a[i] << ((i==n-1)? "\n":" ");
    }
    int idx = -1;// 最低及格idx
    for(int i=0; i<n; i++){
        if(a[i] >= 60){
            idx = i;
            break;
        }  
    }
    if(idx == -1){
        cout << a[n-1] << endl;
        cout << "worst case" << endl;
    } else if(idx == 0){
        cout << "best case" << endl;
        cout << a[0];
    } else{
        cout << a[idx-1] << endl;
        cout << a[idx] << endl;
    }
    return 0;
}
```
:::
:::spoiler 解法二：由大到小找，只紀錄第一個不及格分數的idx，三種情境分別輸出
```cpp=
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    for(int i=0; i<n; i++){
        cout << a[i] << ((i==n-1)? "\n":" ");
    }
    int idx = -1;// 最高不及格idx
    for(int i=n-1; i>=0; i--){
        if(a[i] < 60){
            idx = i;
            break;
        }  
    }
    if(idx == n-1){
        cout << a[n-1] << endl;
        cout << "worst case" << endl;
    } else if(idx == -1){
        cout << "best case" << endl;
        cout << a[0];
    } else{
        cout << a[idx] << endl;
        cout << a[idx+1] << endl;
    }
    return 0;
}
```
:::

:::spoiler 解法三：直接紀錄最小值與最大值
```cpp=
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    for(int i=0; i<n; i++){
        cout << a[i] << ((i==n-1)? "\n":" ");
    }
    int max_score = -1, min_score = 101;
    for(int i=0; i<n; i++){
        if(a[i] < 60){
            if(a[i] > max_score)
                max_score = a[i];
        }
        else{
            if(a[i] < min_score)
                min_score = a[i];
        }
    }
    if(min_score == 101)
        cout << "best case" << endl;
    else
        cout << min_score << endl;
    if(max_score == -1)
        cout << "worst case" << endl;
    else
        cout << max_score << endl;
    return 0;
}
```
:::

> 我只是測試[name=賴楷宗][time=Wed, Mar 10, 2021 9:51 PM][color=#01069b]

> 酷耶樓上是藍色的[color=#121212]

> 上面黑色的也好帥