Kattis - Game Rank
Picture by Gonkasth on DeviantArt, cc by-nd
The gaming company Sandstorm is developing an online two player game. You have been asked to implement the ranking system. All players have a rank determining their playing strength which gets updated after every game played. There are 1 the second highest rank, and Legend the highest rank.

Each rank has a certain number of “stars” that one needs to gain before advancing to the next rank. If a player wins a game, she gains a star. If before the game the player was on rank 25, and this was the third or more consecutive win, she gains an additional bonus star for that win. When she has all the stars for her rank (see list below) and gains another star, she will instead gain one rank and have one star on the new rank.

For instance, if before a winning game the player had all the stars on her current rank, she will after the game have gained one rank and have 1 star on the new rank.

If a player on rank 20 with no stars will have no effect).

If a player reaches the Legend rank, she will stay legend no matter how many losses she incurs afterwards.

The number of stars on each rank are as follows:

  • Rank 2 stars

  • Rank 3 stars

  • Rank 4 stars

  • Rank 5 stars

A player starts at rank 25 with no stars. Given the match history of a player, what is her rank at the end of the sequence of matches?

Input

The input consists of a single line describing the sequence of matches. Each character corresponds to one game; ‘W’ represents a win and ‘L’ a loss. The length of the line is between 10000 characters (inclusive).

Output

Output a single line containing a rank after having played the given sequence of games; either an integer between Legend”.

Sample Input 1 Sample Output 1
WW
25
Sample Input 2 Sample Output 2
WWW
24
Sample Input 3 Sample Output 3
WWWW
23
Sample Input 4 Sample Output 4
WLWLWLWL
24
Sample Input 5 Sample Output 5
WWWWWWWWWLLWW
19
Sample Input 6 Sample Output 6
WWWWWWWWWLWWL
18

题意

25级升24级,要两颗星,但是不是两颗星满了升24,是3颗星才升级变成24级一星。然后24到23到……一直到20都是两颗星,然后3颗星 4颗星 5颗星,然后你20级以下是不掉级的,输了也不掉,如果你是20级0星不会掉星,但是20级一颗星就会掉,你掉级条件是,当前星数为0而且输了,那就掉级了,然后,他还有一个设定,如果在5级以下连胜三局或者以上,一局奖励两颗星,然后,一级是顶级,超过了一级就直接输出LEGEND,接下来那个人输成什么样都是LEGEND,其实就是炉石传说的规则

代码

#include<bits/stdc++.h>
using namespace std;
int k[30] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2};
char aa[11000];
int main() {
    int n;
    while (~scanf("%s", aa)) {
        n = strlen(aa);
        int ans = 25, b = 0;
        for (int i = 0; i < n; i++) {
            if (aa[i] == 'W') {
                b++;
                if (i > 1 && aa[i - 1] == 'W' && aa[i - 2] == 'W' && ans >= 6)b++;
                if (b > k[ans]) {
                    b -= k[ans]; ans--;
                }
            } else {
                if (ans > 20 || ans == 20 && b == 0) {
                    continue;
                }
                b--;
                if (b < 0) {
                    ans++; b = k[ans] - 1;
                }
            }
            if (ans == 0)break;
        }
        if (ans) {
            printf("%d\n", ans);
        } else {
            puts("Legend");
        }
    }
    return 0;
}

 

相关文章: