diff --git a/md/0020.md b/md/0020.md new file mode 100644 index 0000000..5e8928a --- /dev/null +++ b/md/0020.md @@ -0,0 +1,33 @@ +เพื่อหาว่าผู้เข้าแข่งขันคนใดเป็นผู้ชนะ เราจะต้องรู้คะแนนรวมของแต่ละคน ซึ่งสามารถหาได้โดยการนำคะแนนที่แต่ละคนได้มารวมกัน ให้ $\text{score[i]}$ เก็บคะแนนรวมของคนที่ $i + 1$ (เนื่องจาก array เริ่มที่ 0) + +จากนั้นเราจะหาว่าคะแนนรวมที่มากที่สุดเป็นเท่าไหร่ และเก็บคำตอบในตัวแปร $\text{max\_score}$ แล้วค่อยหาว่าผู้เข้าแข่งขันคนไหนเป็นคนที่ได้คะแนนเท่ากับ $\text{max\_score}$ + +```cpp +#include +using namespace std; + +int score[5]; + +int main () { + int max_score = 0; + int winner = 0; + + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 4; j++) { + int s; cin >> s; + score[i] += s; + } + } + + for (int i = 0; i < 5; i++) { + max_score = max(max_score, score[i]); + } + + for (int i = 0; i < 5; i++) { + if (max_score == score[i]) winner = i+1; + } + + cout << winner << ' ' << max_score; + return 0; +} +```