-
Notifications
You must be signed in to change notification settings - Fork 0
/
Majstor.cpp
73 lines (66 loc) · 1.61 KB
/
Majstor.cpp
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
72
73
/**
* Jared Bentvelsen
* https://dmoj.ca/problem/crci08p2
* April 29 2020
*/
#include <iostream>
#include <string>
#include <algorithm>
#define ROCK 0
#define PAPER 1
#define SCISSORS 2
int track[51][3];
int play(char m1, char m2){
if(m1 == 'S'){
return m2 == 'S' ? 1 : m2 == 'R' ? 0 : 2;
}
if(m1 == 'R'){
return m2 == 'R' ? 1 : m2 == 'P' ? 0 : 2;
}
if(m1 == 'P'){
return m2 == 'P' ? 1 : m2 == 'S' ? 0 : 2;
}
return -1;
}
int getSuit(int i){
int nR = track[i][ROCK] + 2*track[i][SCISSORS];
int nP = track[i][PAPER] + 2*track[i][ROCK];
int nS = track[i][SCISSORS] + 2*track[i][PAPER];
int s = ROCK;
int max = nR;
if(nP > max){
s = PAPER;
max = nP;
}
if(nS > max){
s = SCISSORS;
}
return s;
}
int main(){
std::string input,opp;
int N, R,scr = 0, mx = 0;
for(int i = 0; i < 51;i++){
for(int j = 0; j < 3;j++){
track[i][j] = 0;
}
}
std::cin >> R >> input >> N;
for(int i = 0; i < N;i++){
std::cin >> opp;
for(int j = 0; j < R;j++){
scr += play(input[j],opp[j]);
track[j][opp[j] == 'S' ? SCISSORS : opp[j] == 'P' ? PAPER : ROCK]++;
}
}
int suit;
for(int i = 0; i < R;i++){
suit = getSuit(i); // The suit to pick
//std::cout<<suit;
mx += 2*track[i][suit == PAPER ? ROCK : suit == ROCK ? SCISSORS : PAPER];
mx += track[i][suit];
}
std::cout << scr << "\n";
std::cout << mx;
return 0;
}