残月之肃-C++

题目描述:
小D励志成为月男绝活哥,为了更熟练的掌握“控刀”机制,他决定编写一个程序来辅助他学习。
控刀的机制如下:
1、月男一共有5把武器,为了简单起见,我们用 A、B、C、D、E 来表示。月男初始的武器队列按照 A、B、C、D、E 的顺序排列。
2、月男的武器最大容量均为50发子弹。
3、任意时刻,月男会同时持有2把武器,其中一把在手上(Main Hand) 负责攻击,此时另一把在背后(Off Hand) 等待切换(由规则1可知,初始会从武器队列中将AB两把武器发给月男,其中,A在手上,B在背后)。当使用w技能时,月男会交换这两把武器,被交换的武器仍保持交换前的子弹数。
4、当月男手上的枪子弹打光时,手上的枪会放置回武器队列的最后,等待下次获取;同时,当前武器队列的第一把枪刷新到月男手上,子弹数初始化为50;
5、我们的操作序列共有3种字符组成
a: 月男使用手上的武器进行攻击,消耗1发子弹。
q: 月男使用手上的武器使用技能,消耗10发子弹。
w: 月男切换手上和背后的武器(即,原本位于手上的武器将置于背后,背后的武器切换到手上),不消耗子弹。
6、当月男手上的枪子弹数大于0但小于10时,可以使用技能,使用技能后与规则4中,子弹打光的效果相同,没有额外的判断。
现在,我们给出你一个长度为N的操作序列,请你告诉我按照序列执行后,月男最终的状态。
输入描述:
输入第一行包含一个整数N(N≤10^6)
输入第二行一个长度为N的字符串,表示操作序列。
输出描述:
输出包含两行,每行由一个字符和一个整数组成,字符和整数间由一个空格隔开,表示月男最后的状态。
输出第一行表示月男当前手上的武器编号及剩余子弹。
输出第一行表示月男当前背后的武器编号及剩余子弹。
样例输入 1
20
qwwwaqwwwaqaaqqwwawq
样例输出 1
B 29
A 6

#include <iostream>
#include <string>
using namespace std;

int arr[2][5] = { {1,2,3,4,5},{50,50,50,50,50 } };

int main() {
    int N;
    cin >> N;
    string str;
    cin >> str;
    
    // Initial hands
    int mainHandIndex = 0;
    int offHandIndex = 1;
    
    for (const char op : str) {
        if (op == 'a') {
            // Attack with main hand
            arr[1][mainHandIndex]--;
            if (arr[1][mainHandIndex] == 0) {
                // Main hand weapon out of bullets, swap as per rule
                swap(arr[0][mainHandIndex], arr[0][(mainHandIndex + 1) % 5]);
                swap(arr[1][mainHandIndex], arr[1][(mainHandIndex + 1) % 5]);
            }
        } else if (op == 'q') {
            // Use skill with main hand
            if (arr[1][mainHandIndex] > 10) {
                arr[1][mainHandIndex] -= 10;
            } else {
                arr[1][mainHandIndex] = 0;
                // Main hand weapon out of bullets, swap as per rule
                swap(arr[0][mainHandIndex], arr[0][(mainHandIndex + 1) % 5]);
                swap(arr[1][mainHandIndex], arr[1][(mainHandIndex + 1) % 5]);
            }
        } else if (op == 'w') {
            // Swap main hand and off hand
            swap(mainHandIndex, offHandIndex);
        }
    }
    
    // Output final state
    cout << char('A' + arr[0][mainHandIndex] - 1) << " " << arr[1][mainHandIndex] << endl;
    cout << char('A' + arr[0][offHandIndex] - 1) << " " << arr[1][offHandIndex] << endl;
    
    return 0;
}
  • 9
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值