โจทย์
Each row of scores holds one student's test scores. Compute each student's average with a helper function and return the row index of the student with the highest average. If several tie, return the smallest index.
Implement top_student(scores).
Input
scores: One row of scores per student; every row has at least one score.
Output
Return the index of the top student.
เงื่อนไข
1 ≤ students ≤ 1,000; 1 ≤ scores per student ≤ 100; 0 ≤ score ≤ 100
ตัวอย่าง
อินพุต:
scores = [
[80, 90],
[95, 85],
[70, 100]
]
ผลลัพธ์ที่คาดหวัง:
expected = 1
อินพุต:
std::vector<std::vector<long long>> scores = {
{80, 90},
{95, 85},
{70, 100}
};
ผลลัพธ์ที่คาดหวัง:
long long expected = 1;
อินพุต:
long[][] scores = new long[][] {
new long[] {80, 90},
new long[] {95, 85},
new long[] {70, 100}
};
ผลลัพธ์ที่คาดหวัง:
long expected = 1;
คำอธิบาย
Averages are 85, 90 and 85, so student 1 has the highest average.
อินพุต:
scores = [
[60],
[60, 60]
]
ผลลัพธ์ที่คาดหวัง:
expected = 0
อินพุต:
std::vector<std::vector<long long>> scores = {
{60},
{60, 60}
};
ผลลัพธ์ที่คาดหวัง:
long long expected = 0;
อินพุต:
long[][] scores = new long[][] {
new long[] {60},
new long[] {60, 60}
};
ผลลัพธ์ที่คาดหวัง:
long expected = 0;
คำอธิบาย
Both averages are 60; the tie goes to the smaller index, 0.
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน