数组取第三个走了几步
同样数「走了几步」,这次换成数组(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 编译。)
全部评论