第一场-G-Game Rank

题目链接:点击打开链接

(一)题目描述:

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

扫描二维码关注公众号,回复: 436109 查看本文章

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

(二)题目大意:相当于让你模拟一下游戏的升降段位规则。

(三)解题思路:直接模拟,细心一点即可。

(四)具体代码:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
string str;
int lev[26];
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    for(int i=1;i<=10;i++)lev[i]=5;
    for(int i=11;i<=15;i++)lev[i]=4;
    for(int i=16;i<=20;i++)lev[i]=3;
    for(int i=21;i<=25;i++)lev[i]=2;
    while(cin>>str){
        bool is_Legend=0;
        int nowlev=25,nowstar=0,nowcos=0;
        int len=str.length();
        for(int i=0;i<len;i++){
            if(nowlev>20){
                if(str[i]=='L')nowcos=0;
                else {
                    nowcos++;
                    if(nowstar==lev[nowlev]){
                        nowlev--;
                        if(nowcos>=3)nowstar=2;
                        else         nowstar=1;
                    }
                    else if(nowstar==lev[nowlev]-1){
                        if(nowcos>=3){
                            nowlev--;
                            nowstar=1;
                        }
                        else {nowstar++;}
                    }
                    else {
                        if(nowcos>=3)nowstar+=2;
                        else         nowstar+=1;
                    }
                }
            }
            else if(nowlev>=6){
                if(str[i]=='L'){
                    nowcos=0;
                    if(nowlev==20){
                        if(nowstar!=0)nowstar--;
                    }
                    else {
                        if(nowstar==0){nowlev++;nowstar=lev[nowlev]-1;}
                        else nowstar--;
                    }
                }
                else {
                    nowcos++;
                    if(nowstar==lev[nowlev]){
                        nowlev--;
                        if(nowcos>=3)nowstar=2;
                        else         nowstar=1;
                    }
                    else if(nowstar==lev[nowlev]-1){
                        if(nowcos>=3){nowlev--;nowstar=1;}
                        else nowstar++;
                    }
                    else {
                        if(nowcos>=3){nowstar+=2;}
                        else         {nowstar+=1;}
                    }
                }
            }
            else if(nowlev>=1){
                if(str[i]=='L'){
                    nowcos=0;
                    if(nowstar==0){
                        nowlev++;
                        nowstar=lev[nowlev]-1;
                    }
                    else nowstar--;
                }
                else {
                    nowcos++;
                    if(nowstar==lev[nowlev]){
                        nowlev--;
                        if(nowlev==0)break;
                        nowstar=1;
                    }
                    else nowstar++;
                }
            }
            else {is_Legend=1;break;}
        }
        if(nowlev==0)is_Legend=1;
        if(is_Legend)cout<<"Legend"<<endl;
        else cout<<nowlev<<endl;
    }
    return 0;
}

代码巨丑QWQ...

猜你喜欢

转载自blog.csdn.net/xbb224007/article/details/79869502