2020.9.6晚腾讯后台笔试题

感谢大佬激发我做笔试题的欲望,本打算放弃,下午跟大佬讨论腾讯笔试一番后,下定决心决战腾讯笔试。一共A了4道,第二道耗费将近一个小时,导致最后一道连看题的时间都没有😭 贴一下1-4题都代码吧,虽然我是菜鸡,希望大佬们不要笑话😭

//1
#include <iostream>
#include <vector>

using namespace std;

int main() {

    vector<int> arr1;
    vector<int> arr2;

    int n, x;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        arr1.push_back(x);
    }

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        arr2.push_back(x);
    }

    int i = 0;
    int j = 0;

    while (i < arr1.size() && j < arr2.size()) {
        if (arr1[i] == arr2[j]) {
            cout << arr1[i] << " ";
            ++i;
            ++j;
        }
        else if (arr1[i] > arr2[j]) {
            ++i;
        }
        else {
            ++j;
        }
    }
    return 0;
}
//2
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <queue>

using namespace std;

int main() {

    int n, m;
    int x, num;
    int index = 0;
    cin >> n >> m;

    set<int> res;
    queue<int> vals;
    vector<set<int>> elems; //组对应的元素
    map<int, set<int>> ms; //元素所对应的组

    for (int i = 0; i < m; ++i) {
        cin >> x;
        set<int> ts;
        for (int j = 0; j < x; ++j) {
            cin >> num;
            ts.insert(num);
            ms[num].insert(index);
        }
        elems.push_back(ts);
        ++index;
    }

    vals.push(0);
    while (!vals.empty()) {
        int size = vals.size();
        for (int i = 0; i < size; ++i) {
            int cur = vals.front();
            vals.pop();
            for (auto item : ms[cur]) {
                for (auto item_ : elems[item]) {
                    if (res.find(item_) == res.end()) {
                        res.insert(item_);
                        vals.push(item_);
                    }
                }
            }
        }
    }

    cout << res.size();

    return 0;
}
//3
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

struct Node {
    string str;
    int count;
    Node(string &str) : str(str), count(1) {};
};


int main() {

    int n, k;
    int index = 0;
    string str;
    vector<Node> nodes;
    map<string, int> indexs;

    cin >> n >> k;

    for (int i = 0; i < n; ++i) {
        cin >> str;
        if (indexs.find(str) == indexs.end()) {
            indexs.insert({str, index++});
            nodes.push_back(Node(str));
        }
        else {
            nodes[indexs[str]].count++;
        }
    }

    sort(nodes.begin(), nodes.end(), [](const Node &n1, const Node &n2) {
        if (n1.count == n2.count) {
            return n1.str < n2.str;
        }
        return n1.count > n2.count;
    });

    for (int i = 0; i < k; ++i) {
        cout << nodes[i].str << " " << nodes[i].count << endl;
    }

    sort(nodes.begin(), nodes.end(), [](const Node &n1, const Node &n2) {
        if (n1.count == n2.count) {
            return n1.str < n2.str;
        }
        return n1.count < n2.count;
    });

    for (int i = 0; i < k; ++i) {
        cout << nodes[i].str << " " << nodes[i].count << endl;
    }

    return 0;
}
//4
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

    int n;
    int x;
    int minIndex = -1;
    vector<int> array;
    vector<int> array_;
    cin >> n;
    minIndex = n / 2;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        array.push_back(x);
        array_.push_back(x);
    }

    sort(array_.begin(), array_.end());

    for (int i = 0; i < n; ++i) {
        if (array[i] < array_[minIndex]) {
            cout << array_[minIndex] << endl;
        }
        else {
            cout << array_[minIndex - 1] << endl;
        }
    }

    return 0;
}





#笔试题目##腾讯#
全部评论
这一共时间多久呀
点赞 回复 分享
发布于 2020-10-31 01:57
第二题思路是怎么样的能具体说下吗,我看和我想法很像,但是没注释有点难看懂,望指教!
点赞 回复 分享
发布于 2020-09-07 10:48

相关推荐

咦哟,从去年八月份开始长跑,两处实习转正都失败了,风雨飘摇,终于拿到offer了更新一下面试记录:秋招:多部门反复面试然后挂掉然后复活,具体问了啥已经忘了,只是被反复煎炸,直至焦香😋春招:base北京抖音hr打来电话说再次复活,准备面试,gogogo北京抖音一面:六道笔试题:1.promise顺序2.定义域问题3.flat展开4.并发请求5.岛屿数量算法(力扣)深度,广度都写6.忘记了,好像也是算法,难度中等其他问题多是框架底层设计,实习项目重难点~~~秒过😇北京抖音二面:三道笔试题:(为什么只有三道是因为第三道没做出来,卡住了)1.中等难度算法(忘记啥题了,应该是个数组的)2.认识js的继承本质(手写继承模式,深入js的面相对象开发)3.手写vue的响应式(卡在了watch,导致挂掉)---后知后觉是我的注册副作用函数写得有问题,有点紧张了其他题目多是项目拷打,项目亮点,对实习项目的贡献~~~第二天,挂,but立马复活转战深圳客服当天约面深圳客服一面:六道笔试题,由于面过太多次字节,面试官叫我直接写,不用讲,快些写完😋,具体都是些继承,深拷贝(注意对数组对象分开处理,深层次对象,循环引用),加中等难度算法题~~~秒过深圳客服二面:口诉八股大战:大概囊括网络,浏览器渲染原理,动画优化,时间循环,任务队列等等(你能想到的简单八股通通拉出来鞭尸😋)算法题:笔试题6道:1:找出数组内重复的数,arr[0]-arr[n]内的数大小为[1-n],例如[1,2,2,3,3]返回[2,3],要求o(n),且不使用任何额外空间(做到了o(n),空间方面欠佳,给面试官说进入下一题,做不来了)2:原滋原味的继承(所以继承真滴很重要)3:力扣股票购买时机难度中等其他滴也忘记了,因为拿到offer后鼠鼠一下子就落地了,脑子自动过滤掉可能会攻击鼠鼠的记忆😷~~~秒过深圳客服三面:项目大战参与战斗的人员有:成员1:表单封装及其底层原理,使用成本的优化,声明式表单成员2:公司内部库生命周期管理成员3:第三方库和内部库冲突如何源码断点调试并打补丁解决成员4:埋点的艺术成员5:线上项目捷报频传如何查出内鬼成员6:大文件分片的风流趣事成员7:设计模式对对碰成员8:我构建hooks应对经理的新增的小需求的故事可能项目回答的比较流利,笔试题3道,都很简单,相信大家应该都可以手拿把掐😇~~~过过过无hr面后续煎熬等待几天直接hr打电话发offer了,希望大家也可以拿到自己心仪的offer
法力无边年:牛哇,你真是准备得充分,我对你没有嫉妒,都是实打实付出
查看19道真题和解析
点赞 评论 收藏
分享
有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
评论
1
9
分享

创作者周榜

更多
牛客网
牛客企业服务