-
Notifications
You must be signed in to change notification settings - Fork 2
/
GameRank.cs
73 lines (63 loc) · 1.65 KB
/
GameRank.cs
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
/*
Problem: https://open.kattis.com/problems/gamerank
Author: Adrian Reithaug
Submitted: September 3rd, 2017
Time: 0.02s / 1.00s
*/
using System;
namespace Kattis
{
class GameRank
{
static void Main(string[] args)
{
string games = Console.ReadLine();
int rank = 25;
int stars = 0;
int concurrentWins = 0;
for (int i = 0; i < games.Length && rank != 0; i++)
{
if (games[i] == 'W')
{
concurrentWins++;
stars += (concurrentWins >= 3 && rank >= 6) ? 2 : 1;
if (stars > StarsRequired(rank))
{
stars -= StarsRequired(rank);
rank--;
}
}
else
{
concurrentWins = 0;
if (rank < 20 || (rank == 20 && stars > 0))
{
stars--;
}
if (stars < 0)
{
rank++;
stars = StarsRequired(rank) - 1;
}
}
}
Console.WriteLine(rank == 0 ? "Legend" : rank.ToString());
}
private static int StarsRequired(int rank)
{
if (rank >= 21)
{
return 2;
}
else if (rank >= 16)
{
return 3;
}
else if (rank >= 11)
{
return 4;
}
return 5;
}
}
}