中点在哪个下标

👁️ 2 人浏览 💬 0 人评论 ❤️ 添加收藏

五个元素的数组。运行下面这段程序:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int mid_index(const vector<int>& a) {
    int slow = 0;
    int fast = 0;
    while (fast + 1 < (int)a.size()) {
        slow += 1;
        fast += 2;
    }
    return slow;
}

int main() {
    cout << mid_index({13, 15, 17, 23, 24}) << endl;
}

(本题用 g++ -std=c++17 -O0 编译。)

提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论
🔒 登录并作答后可看讨论