3.16深信服笔试

C++开发,14 道填空题,填空题有逻辑题,智力题,4 道编程题,编程题均满分。

填空题有一个是给一个数组,让你数一下有几个逆序对,还有一个是和哈希表相关的题。

C卷。回忆版,只回忆了大致,无题面和样例。

第一题,字符串的题,满分代码

这个题感觉有点奇怪

class Solution {
public:
    string get_subst(string st) {
        string ans;
        for (int i = 0; i < (int) st.size(); i++) {
            if (ans.size() > 1 && st[i] == ans.back() && st[i] == ans[(int) ans.size() - 2]) {
                ans.pop_back();
                ans.pop_back();
            } else {
                ans += st[i];
            }
        }
        return ans;
    }
};

第二题,选相差小于 x 的,满分代码

#include "bits/stdc++.h"

using namespace std;
using i64 = int64_t;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    i64 x;
    cin >> n >> x;
    vector<pair<i64, i64>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());

    i64 res = v[0].second, ans = res;
    for (int i = 1; i < n; i++) {
        if (v[i].first - v[i - 1].first > x) {
            res = v[i].second;
        } else {
            res += v[i].second;
        }
        ans = max(ans, res);
    }
    cout << ans << '\n';

    return 0;
}

第三题,LRU 的题,满分代码

#include "bits/stdc++.h"

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, l;
    cin >> n >> l;
    unordered_map<int, list<pair<int, int>>::iterator> mp;
    list<pair<int, int>> lst;

    while (l--) {
        char o;
        cin >> o;
        if (o == 's') {
            int x, v;
            cin >> x >> v;
            
            if (mp.count(x)) {
                auto it = mp[x];
                lst.splice(lst.begin(), lst, it);
                it->second = v;
            } else {
                if (lst.size() == n) {
                    mp.erase(lst.back().first);
                    lst.pop_back();
                }
                lst.push_front({x, v});
                mp[x] = lst.begin();
            }
        } else {
            int x;
            cin >> x;

            if (mp.count(x)) {
                auto it = mp[x];
                lst.splice(lst.begin(), lst, it);
                cout << it->second << '\n';
            } else {
                cout << "-1\n";
            }
        }
    }

    return 0;
}

第四题,一些数被打乱要求还原的题,满分代码

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1), c(n + 1, -1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        c[b[i]] = i;
    }
    int j = 0;
    for (int i = 1; i <= n; i++) {
        if (c[i] == -1) {
            j = i;
            break;
        }
    }
    vector<int> ans;
    while (j) {
        ans.push_back(a[j]);
        j = b[j];
    }
    for (int i = (int) ans.size() - 1; i >= 0; i--) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

#深信服笔试#
全部评论
今天D卷编程题一模一样,海笔!
点赞 回复 分享
发布于 03-20 21:00 上海

相关推荐

不愿透露姓名的神秘牛友
09-09 14:10
大三,在字节实习两周,被同学举报,辅导员要求回学校怎么办?
我的代码出BUG了:方案1:找领导说明情况然后请个假,回去一天找辅导员报道,见完面直接溜 。方案2:给辅导员卖惨,卖惨内容为家里没钱有贷款+没钱吃饭+心理抑郁+不想活了+社会险恶(同学举报)+想一si了之,例如:.....。长线规划:你这个同学的行为太恶心了,一定暗中收集你这个同学的错误事迹。比如举报课程设计不是他自己做的、比如以后他要是考公,你去考场门口拉横幅说他***,就说你是他好朋友,拉横幅只是为了开玩笑
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
运营你豪哥:1.模板换一个,现在的模板基础信息加个照片已经占了30%的空间。 2.实习经历的描述,按时间倒序标注清楚,选2-3段和你求职意向契合的经历填写。 3.自我评价再改改,要不就删了;怎么感觉自我评价是在介绍你专业的培养体系,看不出重点要突出什么。
听劝,这个简历怎么改
点赞 评论 收藏
分享
评论
3
15
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务