-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasket_scores.cpp
More file actions
71 lines (66 loc) · 1.36 KB
/
basket_scores.cpp
File metadata and controls
71 lines (66 loc) · 1.36 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
using namespace std;
const int NROW = 7, NCOL = 7;
void load_scores(int scores[][NCOL])
{
srand(time(NULL));
for(int i = 0; i < NROW; i++)
{
for(int j = 0; j < NCOL; j++)
{
scores[i][j] = rand () % 41;
}
}
}
void print_scores(int scores[][NCOL])
{
for(int i = 0; i < NROW; i++)
{
for(int j = 0; j < NCOL; j++)
{
cout << scores[i][j] << " ";
}
cout << endl;
}
}
int max_score(int scores[][NCOL])
{
int max_row = 0, max_index_player = 0, max_index_game = 0;
for(int i = 0; i < NROW; i++)
{
int sum = 0;
for(int j = 0; j < NCOL; j++)
{
sum += scores[i][j];
}
if(sum > max_row)
{
max_row = sum;
max_index_player = i;
}
}
int max = 0;
for(int j = 0; j < NCOL; j++)
{
if(scores[max_index_player][j] > max)
{
max = scores[max_index_player][j];
max_index_game = j;
}
}
int final_sum = 0;
for(int i = 0; i < NROW; i++)
{
final_sum += scores[i][max_index_game];
}
return final_sum;
}
int main()
{
int scores[NROW][NCOL];
load_scores(scores);
print_scores(scores);
int somma = max_score(scores);
cout << endl <<"------------";
cout << endl <<somma;
}