现有需求:统计100万条用户访问日志中每个用户ID(字符串类型)的访问次数,要求平均单次插入和查询的时间复杂度为O(1),以下C++实现代码的横线处应依次填入的内容是?

mr787096 单选题 共 个子题
#include <iostream>
#include <unordered_map>
#include <string>
#include <vector>
using namespace std;

// 模拟获取访问日志接口
vector<string> get_logs() { return {}; }

int main() {
    // 存储<用户ID, 访问次数>的统计结果
    _______ cnt_map;
    vector<string> logs = get_logs();
    for (auto& uid : logs) {
        // 对应uid的访问次数+1
        ________;
    }
    return 0;
}
A

map<string, int> 、 cnt_map[uid] += 1

B

unordered_map<string, int> 、 cnt_map[uid]++

C

unordered_map<string, int> 、 cnt_map.insert({uid, cnt_map[uid] + 1})

D

set<string> 、 cnt_map.insert(uid)

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧