数组取第三个走了几步

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

同样数「走了几步」,这次换成数组(vector):

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<string> a = {"阿岚", "小满", "阿泰", "南风"};
    int steps = 0;
    // 数组按下标取:位置直接算出来,一步都不用走
    string x = a[2];
    cout << steps << endl;
}

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

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

                        
👩‍🏫
AI
💬 题目评论

全部评论