题库 / 3060706. 补全代码:for 循环(2024-09)
3060706. 补全代码:for 循环(2024-09)
题目描述
以下C++代码实现位的格雷码,则横线上应填写()。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// 生成 n 位的格雷码
vector<string> generate_graycode(int n) {
vector<string> graycode_list;
if (n <= 0) {
return graycode_list;
}
// 初始1位格雷码
graycode_list.push_back("0");
graycode_list.push_back("1");
// 迭代生成 n 位的格雷码
for (int i = 2; i <= n; i++) {
int current_size = graycode_list.size();
for (int j = current_size - 1; j >= 0; j--) {
graycode_list.push_back("1" + graycode_list[j]);
}
for (int j = 0; j < current_size; j++) {
———————————————————————— // 在此处填入代码
}
}
return graycode_list;
}
作答说明
单选题:在选项里选出唯一正确的一项,提交后立即判定。答对得满分,答错可以重新提交(两次提交之间需要间隔 20 秒)。
题目来源
CCF GESP 2024 年 9 月认证 C++ 6 级试题,第 7 题。