Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions md/0020.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
เพื่อหาว่าผู้เข้าแข่งขันคนใดเป็นผู้ชนะ เราจะต้องรู้คะแนนรวมของแต่ละคน ซึ่งสามารถหาได้โดยการนำคะแนนที่แต่ละคนได้มารวมกัน ให้ $\text{score[i]}$ เก็บคะแนนรวมของคนที่ $i + 1$ (เนื่องจาก array เริ่มที่ 0)

จากนั้นเราจะหาว่าคะแนนรวมที่มากที่สุดเป็นเท่าไหร่ และเก็บคำตอบในตัวแปร $\text{max\_score}$ แล้วค่อยหาว่าผู้เข้าแข่งขันคนไหนเป็นคนที่ได้คะแนนเท่ากับ $\text{max\_score}$

```cpp
#include<bits/stdc++.h>
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;
}
```