酷代码 AI
菜单
服务商

C++实现根据奥兹玛之心数字信号确定前进方向和总路程

```cpp #include <iostream> using namespace std; int main() { int n; cin >> n; int totalDistance = 0; for (int i = 0; i < n; i++) { int num; cin >> num; if (num % 3 == 0) { cout << "W3" << endl; totalDistance += 3; } else if (num % 5 == 0) { cout << "E5" << endl; totalDistance += 5; } else { cout << "N10" << endl; totalDistance += 10; } } cout << totalDistance << endl; return 0; } ``` 上述代码首先读取信号数字的个数`n`,接着使用`for`循环读取每个信号数字。对于每个信号数字,判断其是 3 的倍数、5 的倍数还是其他情况,分别输出对应的前进方向和距离,并累加总路程。最后输出总路程。 ######[AI问答 | 265点数解答 | 2026-05-16 20:05:14]

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