#1771. 珅泽教育CSP-J第一轮模拟考第八套 第 30 题
珅泽教育CSP-J第一轮模拟考第八套 第 30 题
第三题
struct hash_map
{
const int max_size = 32767;
struct node
{
int key;
int value;
int next;
}
map[max_size * 4];
int size = 0;
int hash[max_size] = {0};
int& operator[] (int key)
{
int code = key % max_size;
int addr = hash[code];
while (addr > 0)
{
if (map[addr].key == key)
return map[addr].value;
else
addr = map[addr].next;
}
++size;
map[size].key = key;
map[size].value = 0;
map[size].next = hash[code];
hash[code] = size;
return map[size].value;
}
};
void test(int q)
{
hash_map map;
while (q > 0)
{
--q;
char op;
std::cin >> op;
if (op == '+')
{
int key, value;
std::cin >> key >> value;
map[key] = value;
}
if (op == '?')
{
int key;
std::cin >> key;
std::cout << map[key] << "\n";
}
}
}
判断题
当重复执行 + 1 2 四遍的时候,hash_map 的 size 将会增加 4( )。
{{ select(1) }}
- 正确
- 错误