五个人占了几个格子
运行下面这段程序(链地址法,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 编译。)
全部评论