-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoofPaperScissors.java
More file actions
53 lines (53 loc) · 1.1 KB
/
HoofPaperScissors.java
File metadata and controls
53 lines (53 loc) · 1.1 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
import java.io.*;
public class HoofPaperScissors {
public static void main(String[] args) throws IOException
{
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("hps.in"));
int N = Integer.parseInt(br.readLine());
char[] plays = new char[N];
char play;
int H = 0;
int P = 0;
int S = 0;
for (int i = 0; i < N; i++)
{
play = br.readLine().charAt(0);
plays[i] = play;
if (play == 'H')
H++;
else if (play == 'P')
P++;
else
S++;
}
int Sbef = 0; int Hbef = 0; int Pbef = 0;
int max = Math.max(H, Math.max(P, S));
int getSum;
for (int i = 0; i < N; i++)
{
if (plays[i] == 'H')
{
Hbef++;
H--;
}
else if (plays[i] == 'P')
{
Pbef++;
P--;
}
else
{
Sbef++;
S--;
}
getSum = Math.max(H, Math.max(P, S)) + Math.max(Hbef, Math.max(Pbef, Sbef));
max = Math.max(getSum, max);
}
//System.out.println(max);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("hps.out")));
pw.println(max);
pw.close();
br.close();
}
}