• GYM 101550 G.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 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

    分析:

    一个游戏级别分2525级和额外等级LegendLegend,其中2525级最低级,11级次高级,LegendLegend最高级,每个级别对应一个星星数量,对应表如下:

    • Rank 25-21: 2 stars
    • Rank 20-16: 3 stars
    • Rank 15-11: 4 stars
    • Rank 10-1: 5 stars

    规则如下:

    W:rk大于等于6小于等于25且3连胜的话,star加2,否则加一

    stai满了之后,晋级:比如23级,2颗星再加上两颗星就是22,两颗星!

    L:rk大于20的话,输了也不掉star

    rk小于等于20,且star!=0的话,减少一颗星

    rk<20且star==0的话,掉级,star数等于改级star总数-1

    写了很久啊,妈卖批,规则很模糊

     code:

    #include<iostream>
    using namespace std;
    int rk,star,flag;
    void down()
    {
        if(rk>20)
            return ;
        if(star)
        {
            star--;
            return ;
        }
        if(rk<20)
        {
            rk++;
            if(rk>=16&&rk<=20)
                star=2;
            else if(rk>=11&&rk<=15)
                star=3;
            else if(rk>=1&&rk<=10)
                star=4;
        }
    }
    void up(int v)
    {
        star+=v;
        if(rk>=21&&rk<=25&&star>2)
        {
            rk--;
            star-=2;
        }else if(rk>=16&&rk<=20&&star>3)
        {
            rk--;
            star-=3;
        }else if(rk>=11&&rk<=15&&star>4)
        {
            rk--;
            star-=4;
        }else if(rk>=1&&rk<=10&&star>5)
        {
            rk--;
            star-=5;
        }
    }
    void f(string str)
    {
        int l=str.length();
        for(int i=0;i<l;i++)
        {
            if(rk==0)
                break;
            if(str[i]=='W')
            {
                flag++;
                if(rk>=6&&flag>=3)
                {
                    up(2);
                }else
                {
                    up(1);
                }
            }else
            {
                down();
                flag=0;
            }
        }
    }
    int main()
    {
        string str;
        while(cin>>str)
        {
            rk=25,star=0,flag=0;//初始化
            f(str);
            if(rk)
            {
                cout<<rk<<endl;
            }else
            {
                cout<<"Legend"<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    [每日一讲] Python系列:浅拷贝与深拷贝
    [每日一讲] Python系列:变量、内存管理与传递
    [每日一讲] Python系列:字典
    [每日一讲] Python系列:列表与元组
    [已开源/文章教程]独立开发 一个社交 APP 的源码/架构分享 (已上架)
    从选择到上传,可能是最贴心的高仿朋友圈编辑了
    完整的社交app源码android+laravel
    基于Laravel+Swoole开发智能家居后端
    APP架子迁移指南(三)
    Laravel如何优雅的使用Swoole
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9353571.html
Copyright © 2020-2023  润新知