五个人占了几个格子

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

运行下面这段程序(链地址法,8 格):

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

using Row = pair<int, string>;
using Table = vector<vector<Row>>;   // 每一格挂一串 (学号, 名字)

const vector<Row> FIVE = {{17, "阿岚"}, {24, "小满"}, {15, "阿泰"}, {13, "南风"}, {23, "北辰"}};

int main() {
    Table table(8);
    for (const Row& r : FIVE) table[r.first % 8].push_back(r);
    int n = 0;
    for (const auto& cell : table) if (!cell.empty()) n++;
    cout << n << endl;
}

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

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

                        
👩‍🏫
AI
💬 题目评论

全部评论