## C. 歷史成績(History Score)
:::info
- [x] 出題完畢
- [x] 標題
- [x] 構題想法
- [x] 題目敘述
- [x] 輸入說明 + 測資範圍 + 測資配分
- [x] 輸出說明
- [x] Sample Input & Output *3
- [x] 提示
- [x] 標籤
- [x] 參考解法
- [x] 生測資上傳
- [x] 配分與時間
- [x] 審題
- [x] 前測
- [x] 驗題
:::
### 題目敘述
拿到學期成績單的 $ShiYu$ 很擔心自己的歷史科被當掉,於是他拿著成績找到了老師詢問自己的成績是否會被當,老師說:
「我有一個自訂的評斷標準:三次段考成績中取最高的那次佔總成績中的 $60 \%$,而平時成績則佔 $40 \%$。
只要總成績 $> 60$ 我就不會當你,否則『你會被當』,而且如果你的總成績 $\le 40$,『你會被死當的』!」。
請你設計一份程式碼,依據老師自訂的評斷標準,算出 $ShiYu$ 的歷史總成績,並判斷 $ShiYu$ 是否會被當。
出題者:$ShiYu.$
### 輸入說明
第一行有 4 個正整數以空格隔開
> a b c d
- a:第一次段考成績
- b:第二次段考成績
- c:第三次段考成績
- d:平時成績
測資範圍限制:
$0 \le a,b,c,d \le 100$
### 輸出說明
依據老師自訂的評斷標準:$總成績 =
三次段考成績取最高的那次 \times 0.6 \ + 平時成績 \times 0.4$
如果不會被當 請輸出:You passed.
但如果會被當 請輸出:You will be down.
且若會被死當 請輸出:You will be stunned.
每一筆測資只會有一種結果
| Sample Input#1 | Sample Output#1 |
| -------------- | --------------- |
| 50 39 48 76 | You passed. |
| Sample Input#2 | Sample Output#2 |
| -------------- | ----------------- |
| 39 48 50 75 | You will be down. |
| Sample Input#3 | Sample Output#3 |
| -------------- | ----------------- |
| 31 36 20 47 | You will be down. |
| Sample Input#4 | Sample Output#4 |
| -------------- | -------------------- |
| 36 20 31 46 | You will be stunned. |
### 提示
範例測資說明
範測 1:
三次段考最高分 = 50,平時成績 = 76
總成績 $= 50 \times 0.6 \ + 76 \times 0.4 = 60.4$
因為 60.4 > 60 成立,所以輸出 You passed.
範測 2:
三次段考最高分 = 50,平時成績 = 75
總成績 $= 50 \times 0.6 \ + 75 \times 0.4 = 60$
因為 $60 > 60$ 不成立,所以輸出 You will be down.
範測 3:
三次段考最高分 = 36,平時成績 = 47
總成績 $= 36 \times 0.6 \ + 47 \times 0.4 = 40.4$
因為 $40.4 > 60$ 不成立 且 $40.4 > 40$ 成立,所以輸出 You will be down.
範測 4:
三次段考最高分 = 36,平時成績 = 46
總成績 $= 36 \times 0.6 \ + 46 \times 0.4 = 40$
因為 $40 \le 40$ 成立,所以輸出 You will be stunned.
找最大值可以使用 max( ) 函數 但要取三次段考成績的最大值 該怎麼做呢?
如果分數只拿到 NA80% 請思考一下要用哪個變數型別才能準確算出帶有小數點的總成績呢?
請注意你寫的判斷式是否與題目的自訂評判標準邏輯相同
並注意你輸出的字串是否與輸出說明完全符合 盡量用複製的才不會打錯
> 這題沒用 double 只會有 80 分
### 標籤
變數,最大值,四則運算,多重判斷式
### 參考解法
```cpp=
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d; cin >> a >> b >> c >> d;
double score = max(max(a,b),c) * 0.6 + d * 0.4;
if (score > 60) {
cout << "You passed.\n";
} else if (score > 40) {
cout << "You will be down.\n";
} else {
cout << "You will be stunned.\n";
}
return 0;
}
```
---
### 測資生成
及格
```cpp=
void make() {
int a = randint() % 30 + 40;
int b = randint() % 30 + 40;
int c = randint() % 30 + 40;
cout << a << " " << b << " " << c << " ";
double m = max(max(a,b),c);
double r = (60 - (m * 0.6)) / 0.4;
int d = randint() % (int)(100-r) + r + 1;
cout << d << endl;
}
```
被當
```cpp=
void make() {
int a = randint() % 30 + 30;
int b = randint() % 30 + 30;
int c = randint() % 30 + 30;
cout << a << " " << b << " " << c << " ";
double m = max(max(a,b),c);
double l = (40 - (m * 0.6)) / 0.4;
double r = (60 - (m * 0.6)) / 0.4;
int d = randint() % (int)(r-l-1) + l;
cout << d << endl;
}
```
被死當
```cpp=
void make() {
int a = randint() % 20 + 10;
int b = randint() % 20 + 10;
int c = randint() % 20 + 10;
cout << a << " " << b << " " << c << " ";
double m = max(max(a,b),c);
double r = (40 - (m * 0.6)) / 0.4;
int d = randint() % (int)(r-1) + 1;
cout << d << endl;
}
```