酷代码 AI
菜单
服务商

用C++寻找非负整数序列中最大值的下标

```cpp #include <iostream> using namespace std; int main() { int n; cin >> n; int a[1000]; for (int i = 0; i < n; i++) { cin >> a[i]; } int maxIndex = 0; for (int i = 1; i < n; i++) { if (a[i] > a[maxIndex]) { maxIndex = i; } } cout << maxIndex + 1; return 0; } ``` 此代码先读取序列个数 `n` 和 `n` 个非负整数存于数组 `a`。接着遍历数组,通过比较找出最大值对应的下标 `maxIndex`。最后输出该下标(下标从1开始)。 ######[AI问答 | 209点数解答 | 2026-04-11 19:47:39]

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