第 7 格里挤了几个
五个人按学号放进一张 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);
cout << table[7].size() << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)
全部评论