Gym 101550G (CSU 2018) 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

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

一道简单模拟题,仔细考虑各种情况就行

#include
#include
#include
#include
using namespace std;

int main()
{
	string a;
	int flag1, level, star;
	while (cin >> a)
	{
		flag1 = 0;
		level = 25;
		star = 0;
		for (int i = 0; i < a.length(); i++)
		{
			if (a[i] == 'W'&&flag1 == 0)//前面没赢过
			{
				star += 1;
				flag1 = 1;
			}
			else if (a[i] == 'W'&&flag1 == 1)//已经赢了一把
			{
				star += 1;
				flag1 = 2;
			}
			else if (a[i] == 'W'&&flag1 == 2&&level>=6)//已经连胜两把以上
			{
				star += 2;
			}
			else if (a[i] == 'W')
			{
				star += 1;
			}
			else if (a[i] == 'L'&&level<=20)//输了且等级为1-20
			{
				star -= 1;
				flag1 = 0;
			}
			else if (a[i] == 'L')//输了且等级为21-25
			{
				flag1 = 0;
			}
			if (level<=25&&level>=21)
			{
				if (star > 2)
				{
					level -= 1;
					star -= 2;
				}
				if (star<0)
				{
					star = 0;
				}
			}
			else if (level <= 20 && level >= 16)
			{
				if (star > 3)
				{
					level -= 1;
					star -= 3;
				}
				else if (star < 0 && level != 20)
				{
					level += 1;
					star = 2;
				}
				else if (star <0)
				{
					star = 0;
				}
			}
			else if (level<=15&&level>=11)
			{
				if (star>4)
				{
					level -= 1;
					star -= 4;
				}
				else if (star < 0&&level!=15)
				{
					level += 1;
					star = 3;
				}
				else if (star<0)
				{
					level += 1;
					star = 2;
				}
			}
			else if (level >= 1 && level <= 10)
			{
				if (star>5)
				{
					level -= 1;
					star -= 5;
				}
				else if (star < 0&&level!=10)
				{
					level += 1;
					star = 4;
				}
				else if (star<0)
				{
					level += 1;
					star = 3;
				}
			}
		}
		if (level != 0)
			cout << level << endl;
		else
			cout << "Legend" << endl;
	}
	return 0;
}

 

你可能感兴趣的:(CSUOJ,Gym)