-
Notifications
You must be signed in to change notification settings - Fork 4
/
GameRank.java
88 lines (73 loc) · 1.53 KB
/
GameRank.java
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Game Rank
Written by: Tim Wayburn, Joel Vikström and Jacob Adlers
*/
public class GameRank{
public static void main(String[] args){
Kattio io = new Kattio(System.in, System.out);
String sequence = io.getWord();
int rank = 25;
int currstars = 0;
int streak = 0;
for(int i = 0; i < sequence.length(); i++){
if(rank == 0){
io.println("Legend");
io.close();
return;
}
char currentresult = sequence.charAt(i);
int starsrequired = starsrequired(rank);
if(currentresult == 'W'){
streak++;
if (streak >= 3 && rank>=6) {
currstars += 2;
}
else {
currstars ++;
}
if (currstars > starsrequired) {
rank--;
currstars -= starsrequired;
}
}
else { // Lose
streak = 0;
if (rank == 20) {
if (currstars>0) {
currstars --;
}
}
else if (rank < 20) {
if (currstars == 0) {
rank ++;
currstars = starsrequired(rank)-1;
}
else {
currstars--;
}
}
}
}
if(rank == 0){
io.println("Legend");
}
else {
io.println(rank);
}
io.close();
}
public static int starsrequired(int rank){
if(rank >= 21){ // 25-21
return 2;
}
else if(rank >= 16){ //20-16
return 3;
}
else if(rank >= 11){ // 15-11
return 4;
}
else{ // 10-1
return 5;
}
}
}