-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsenate.cpp
More file actions
66 lines (60 loc) · 1.15 KB
/
senate.cpp
File metadata and controls
66 lines (60 loc) · 1.15 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
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
// Senate task
char translate(int i){
char s = char(i+65);
return s;
}
int num_parties(int* arr, int n){
int nonzeros = 0;
for(int i = 0; i < n; i++){
if(arr[i] != 0){
nonzeros++;
}
}
return nonzeros;
}
int max_party(int* arr, int n){
int max = -1;
int argmax = -1;
for(int i = 0; i < n; i++){
if(arr[i] > max){
max = arr[i];
argmax = i;
}
}
return argmax;
}
int main() {
int t, n;
cin >> t;
for(int i = 0; i < t; i++){
cin >> n;
int arr[n];
for(int j = 0; j < n; j++){
cin >> arr[j];
}
cout << "Case #" << i+1 << ":";
while(true){
if(num_parties(arr,n) > 2){
int remove = max_party(arr,n);
arr[remove] -= 1;
cout << " " << translate(remove);
}
else if(num_parties(arr,n) == 2){
int remove[2];
for(int k=0; k<2; k++){
remove[k] = max_party(arr,n);
arr[remove[k]] -= 1;
}
cout << " " << translate(remove[0]) << translate(remove[1]);
}
else{
cout << endl;
break;
}
}
}
}