残月之肃-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;
}

相关推荐

  1. 残月-C++

    2024-07-18 12:40:01       18 阅读
  2. 单位里,永远要记住这些残忍的处事道!

    2024-07-18 12:40:01       32 阅读
  3. C++函数指针

    2024-07-18 12:40:01       62 阅读
  4. C++ map

    2024-07-18 12:40:01       56 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 12:40:01       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 12:40:01       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 12:40:01       57 阅读
  4. Python语言-面向对象

    2024-07-18 12:40:01       68 阅读

热门阅读

  1. 升本1.0.5-规划-英语-207天

    2024-07-18 12:40:01       21 阅读
  2. CmakeLists

    2024-07-18 12:40:01       25 阅读
  3. C语言:进程间通信

    2024-07-18 12:40:01       19 阅读
  4. OPenCV批量实现直方图均衡化----20240718

    2024-07-18 12:40:01       17 阅读
  5. vue中:class、watch、v-show使用

    2024-07-18 12:40:01       20 阅读