Game Rank

题目描述

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 decreasing 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?

输入

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 1 and 10 000 characters (inclusive).

输出

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

样例输入

WW

样例输出

25

[提交] [状态]

类似于游戏中排位赛的上分规则:每个段位有特定的星级,赢一局得一颗星(输一局减一颗星),满星以后可以上一个段位,当上到“传说”段位以后,即使输也不会再掉星,当段位低于20级或者是20级但是没有星的时候,输了也不会掉星,当连胜的次数大于等于三且段位在6-25之间的时候每赢一局可得一颗额外的星(作为奖励QAQ)。题目不难,关键是读懂题目不容易= =。(瞬间不想玩游戏了,毕竟上分这么难@=@)

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int a[30]={0,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 s[10100];
int ran=25;//段位,初始化为25
int xing=0;//当前段位的星级
int cont=0;//记录连胜次数
void solve()
{
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        if(s[i]=='W')
        {
            cont++;
            xing++;
            if(cont>=3&&ran>=6)
                xing++;
            if(xing>a[ran])
            {
                xing-=a[ran];
                ran--;
            }
        }
        if(s[i]=='L')
        {
            cont=0;
            if(ran>=1&&ran<20)
                xing--;
            if(ran==20&&xing>0)
                xing--;
            if(xing<0&&ran<25)
            {
                ran++;
                xing+=a[ran];
            }
        }
        if(ran<=0)
        {
            cout<<"Legend"<<endl;
            return ;
        }
    }
    cout<<ran<<endl;
    return ;
}
int main()
{
    scanf("%s",s);
    solve();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wangws_sb/article/details/82956336