-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_B1032.cpp
More file actions
43 lines (39 loc) · 876 Bytes
/
3_B1032.cpp
File metadata and controls
43 lines (39 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* P86
*/
#include <iostream>
using namespace std;
int main()
{
int schoolNum;
cout << "Input school number: ";
cin >> schoolNum;
// dynamic array
int *schoolArray = new int(schoolNum);
// read the score
for (int i = 0; i < schoolNum; i++)
{
int schoolId;
int schoolScore;
cin >> schoolId >> schoolScore;
if (schoolId >= schoolNum)
{
cout << "Invalid id. " << endl;
return 0 ;
}
schoolArray[schoolId] += schoolScore;
}
// get max score
int maxScore = 0;
int maxId = 0;
for (int j = 0; j < schoolNum; j++)
{
if (schoolArray[j] > maxScore)
{
maxScore = schoolArray[j];
maxId = j;
}
}
cout << "Max school id and score is: " << maxId << " " << maxScore << endl;
return 0;
}