酷代码 AI
菜单
服务商
DeepSeek字节豆包
更多选项

小核桃攻击模拟:C++实现敌人护盾能量计算

```cpp #include <iostream> using namespace std; int main() { int a[5]; for (int i = 0; i < 5; i++) { cin >> a[i]; } int n; cin >> n; for (int t = 0; t < n; t++) { int type; cin >> type; if (type == 1) { // 粒子炮:所有敌人护盾减5 for (int i = 0; i < 5; i++) { a[i] -= 5; } } else if (type == 2) { // 集束粒子炮 int target; cin >> target; target--; // 转换为0-based索引 // 目标敌人护盾减半 a[target] /= 2; // 左边敌人(如果存在) if (target - 1 >= 0) { a[target - 1] /= 2; } // 右边敌人(如果存在) if (target + 1 < 5) { a[target + 1] /= 2; } } // 负数归零 for (int i = 0; i < 5; i++) { if (a[i] < 0) { a[i] = 0; } } } // 输出结果 for (int i = 0; i < 5; i++) { cout << a[i]; if (i < 4) { cout << " "; } } cout << endl; return 0; } ``` ######[AI问答 | 394点数解答 | 2026-07-07 23:13:15]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]