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;
}

 

package com.cykj.console; import com.cykj.dao.RankingDAO; import com.cykj.dao.SaveDAO; import com.cykj.dao.ScoreDAO; import com.cykj.game.Game; import com.cykj.game.map.Direction; import java.util.List; import java.util.Scanner; /** * @BelongsProject: game2048 * @BelongsPackage: com.cykj.console * @Author: 土里埋埋埋埋埋 * @CreateTime: 2025-11-17 11:42 * @Description: TODO * @Version: 1.0 */ public class GameSession { private static final int FIXED_TIME_LIMIT = 60; private final Scanner scanner; private final ScoreDAO scoreDAO; private final SaveDAO saveDAO; public GameSession(Scanner scanner, ScoreDAO scoreDAO, SaveDAO saveDAO) { this.scanner = scanner; this.scoreDAO = scoreDAO; this.saveDAO = saveDAO; } public void startGame(int userId) throws Exception { MenuManager menuManager = new MenuManager(scanner, new RankingDAO()); int modeChoice = menuManager.showGameModeMenu(); scanner.nextLine(); if (modeChoice == 3) return; boolean isTimedMode = (modeChoice == 2); int timeLimit = isTimedMode ? FIXED_TIME_LIMIT : 0; while (true) { Game game = isTimedMode ? new Game(true, timeLimit) : new Game(); playGame(game, isTimedMode, userId); System.out.println("请选择是否重新开始: 1 - 重新开始 2 - 返回菜单"); int res = scanner.nextInt(); scanner.nextLine(); if (res != 1) break; } } void playGame(Game game, boolean isTimedMode, int userId) throws Exception { List<String> userMaxScore = scoreDAO.maxscore(userId, isTimedMode); while (!game.isGameOver()) { System.out.print("当前分数: " + game.getScore()); System.out.print("\t"); for (String rank : userMaxScore) { System.out.print(rank); } if (isTimedMode) { System.out.print("\t剩余时间: " + game.getRemainingTime() + "秒"); } System.out.println(); displayBoard(game.getBoard()); System.out.println("操作: w(上) s(下) a(左) d(右) q(退出) x(存档) z(撤回)"); System.out.print("输入操作: "); String input = scanner.nextLine().toLowerCase(); handleInput(input, game, isTimedMode, userId); } displayBoard(game.getBoard()); System.out.print(game.isGameOver() ? "游戏结束!" : "时间到!"); System.out.println(" 最终分数: " + game.getScore()); scoreDAO.saveScore(userId, game.getScore(), isTimedMode); } private void handleInput(String input, Game game, boolean isTimedMode, int userId) throws Exception { if (input.equals("q")){ return; } if (input.equals("x")) { System.out.print("输入存档名称: "); String saveName = scanner.nextLine(); saveDAO.saveGame(userId, saveName, game.getBoardState(), game.getScore(), game.isTimedMode(), game.getTimeLimit(), game.getRemainingTime()); System.out.println("游戏已保存!"); return; } if (input.equals("z")) { if (game.canUndo()) { game.undo(); System.out.println("已撤回一步"); } else { System.out.println("无法撤回"); } return; } Direction direction = null; switch (input) { case "w": direction = Direction.UP; break; case "s": direction = Direction.DOWN; break; case "a": direction = Direction.LEFT; break; case "d": direction = Direction.RIGHT; break; default: System.out.println("操作无效"); } if (direction != null) game.move(direction); } private void displayBoard(int[][] board) { for (int i = 0; i < 4; i++) { System.out.print(""); for (int j = 0; j < 4; j++) { System.out.print(board[i][j] == 0 ? "\t0" : "\t" + board[i][j]); } System.out.println(); } } } 退出有问题
11-18
课程设计报告:总体方案设计说明 一、软件开发环境配置 本系统采用C++作为核心编程语言,结合Qt 5.12.7框架进行图形用户界面开发。数据库管理系统选用MySQL,用于存储用户数据与小精灵信息。集成开发环境为Qt Creator,操作系统平台为Windows 10。 二、窗口界面架构设计 系统界面由多个功能模块构成,各模块职责明确,具体如下: 1. 起始界面模块(Widget) 作为应用程序的入口界面,提供初始导航功能。 2. 身份验证模块(Login) 负责处理用户登录与账户注册流程,实现身份认证机制。 3. 游戏主大厅模块(Lobby) 作为用户登录后的核心交互区域,集成各项功能入口。 4. 资源管理模块(BagWidget) 展示用户持有的全部小精灵资产,提供可视化资源管理界面。 5. 精灵详情模块(SpiritInfo) 呈现选定小精灵的完整属性数据与状态信息。 6. 用户名录模块(UserList) 系统内所有注册用户的基本信息列表展示界面。 7. 个人资料模块(UserInfo) 显示当前用户的详细账户资料与历史数据统计。 8. 服务器精灵选择模块(Choose) 对战准备阶段,从服务器可用精灵池中选取参战单位的专用界面。 9. 玩家精灵选择模块(Choose2) 对战准备阶段,从玩家自有精灵库中筛选参战单位的操作界面。 10. 对战演算模块(FightWidget) 实时模拟精灵对战过程,动态呈现战斗动画与状态变化。 11. 对战结算模块(ResultWidget) 对战结束后,系统生成并展示战斗结果报告与数据统计。 各模块通过统一的事件驱动机制实现数据通信与状态同步,确保系统功能的连贯性与数据一致性。界面布局遵循模块化设计原则,采用响应式视觉方案适配不同显示环境。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
D3.js作为一种基于JavaScript的数据可视化框架,通过数据驱动的方式实现对网页元素的动态控制,广泛应用于网络结构的图形化呈现。在交互式网络拓扑可视化应用中,该框架展现出卓越的适应性与功能性,能够有效处理各类复杂网络数据的视觉表达需求。 网络拓扑可视化工具借助D3.js展示节点间的关联结构。其中,节点对应于网络实体,连线则表征实体间的交互关系。这种视觉呈现模式有助于用户迅速把握网络整体架构。当数据发生变化时,D3.js支持采用动态布局策略重新计算节点分布,从而保持信息呈现的清晰度与逻辑性。 网络状态监测界面是该工具的另一个关键组成部分,能够持续反映各连接通道的运行指标,包括传输速度、响应时间及带宽利用率等参数。通过对这些指标的持续追踪,用户可以及时评估网络性能状况并采取相应优化措施。 实时数据流处理机制是提升可视化动态效果的核心技术。D3.js凭借其高效的数据绑定特性,将连续更新的数据流同步映射至图形界面。这种即时渲染方式不仅提升了数据处理效率,同时改善了用户交互体验,确保用户始终获取最新的网络状态信息。 分层拓扑展示功能通过多级视图呈现网络的层次化特征。用户既可纵览全局网络架构,也能聚焦特定层级进行细致观察。各层级视图支持展开或收起操作,便于用户开展针对性的结构分析。 可视化样式定制系统使用户能够根据实际需求调整拓扑图的视觉表现。从色彩搭配、节点造型到整体布局,所有视觉元素均可进行个性化设置,以实现最优的信息传达效果。 支持拖拽与缩放操作的交互设计显著提升了工具的使用便利性。用户通过简单的视图操控即可快速浏览不同尺度的网络结构,这一功能降低了复杂网络系统的认知门槛,使可视化工具更具实用价值。 综上所述,基于D3.js开发的交互式网络拓扑可视化系统,整合了结构展示、动态布局、状态监控、实时数据处理、分层呈现及个性化配置等多重功能,形成了一套完整的网络管理解决方案。该系统不仅协助用户高效管理网络资源,还能提供持续的状态监测与深度分析能力,在网络运维领域具有重要应用价值。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值