CSU-2018

Description

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 25 regular ranks, and an extra rank, “Legend”, above that. The ranks are numbered in decreas- ing order, 25 being the lowest rank, 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 6-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 or 2 stars (depending on whether she got a bonus star) on the new rank. If on the other hand she had all stars except one on a rank, and won a game that also gave her a bonus star, she would gain one rank and have 1 star on the new rank. If a player on rank 1-20 loses a game, she loses a star. If a player has zero stars on a rank and loses a star, she will lose a rank and have all stars minus one on the rank below. However, one can never drop below rank 20 (losing a game at 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 25-21: 2 stars

• Rank 20-16: 3 stars

• Rank 15-11: 4 stars

• Rank 10-1: 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

There will be several test cases. Each case consists of a single line describing the sequence of matches. Each character corre- sponds to one game; ‘W’ represents a win and ‘L’ a loss. The length of the line is between 1 and 10 000 characters (inclusive).

Output

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

Sample Input

WW
WWW
WWWW
WLWLWLWL
WWWWWWWWWLLWW
WWWWWWWWWLWWL

Sample Output

25
24
23
24
19
18

Hint

Source

NCPC2016

 

思路:记录当前等级和已获得的星星

(注意读题:只有在6-25级之间三连胜才有星星奖励;只有小于等于20级才会掉星星;成就到达Legend之后就无所谓等级了)

 

#include<cstdio>
#include<string.h>
int A[30];
char s[10005];

int main()
{
    for (int i = 21; i <= 25; i++)
        A[i] = 2;
    for (int i = 16; i <= 20; i++)
        A[i] = 3;
    for (int i = 11; i <= 15; i++)
        A[i] = 4;
    for (int i = 1; i <= 10; i++)
        A[i] = 5;
    A[0] = 0;

    while (scanf("%s", s) != EOF)
    {
        int sum = 0;    //星星数量
        int r = 25; //等级
        int consecutive = 0;    //连胜次数
        bool legend = false;    //legend标记
        int len = strlen(s);
        for (int i = 0; i < len; i++)
        {
            if (s[i] == 'W')
            {
                consecutive++;
                if (consecutive >= 3 && r >= 6)
                    sum += 2;
                else
                    sum += 1;
                if (sum > A[r])
                {
                    sum -= A[r];
                    r--;
                }
            }
            else
            {
                consecutive = 0;
                if (r <= 20)
                {
                    sum--;
                    if (sum < 0)
                    {
                        if (r == 20)
                            sum = 0;
                        else
                        {
                            r++;
                            sum = A[r] - 1;
                        }
                    }
                }
            }

            if (r == 0)
            {
                legend = true;
                break;
            }
        }
        if (legend)
            printf("Legend\n");
        else
            printf("%d\n", r);
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值