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 上海

相关推荐

04-07 21:58
已编辑
北京师范大学 Java
#软件开发笔面经#14道选择42分,4道编程58分。两个小时,写不完。选择题有一些是智力题。类似于高中数学中,给一些不完全的条件,写出唯一(?)的合理结果。(从草稿纸回想的题目,不一定准确)1.&nbsp;有猎人A,B,C,D,E。有猎物a,b,c,d,e。问每个猎人捕猎了哪个猎物?规则:猎人不捕猎与他同名的猎物。每个猎人都捕猎成功一个猎物。每个猎人都捕猎失败一个猎物。与猎人E捕猎失败的猎物同名的猎人&nbsp;捕猎成功了猎物b。与猎人C捕猎失败的猎物同名的猎人&nbsp;捕猎成功了猎物a。猎人B捕猎失败猎物e。猎人B捕猎成功猎物c。2.&nbsp;有四对夫妻,其中有妻子Y,Z,M,A。有丈夫H,B,LU,LO。写出四队夫妻。规则:H的妻子与Y的丈夫跳舞。LO和A不在跳舞。(?)B在吹小号,M在弹钢琴。A和B都不在跳舞。(?)3.&nbsp;有四个渔夫A,B,K,D,有四艘渔船m,s,d,h。问每个渔夫拥有哪个渔船?规则:每个渔夫只有一条船。渔夫会说错,因为渔夫只了解与他和他的船有关的事情。当渔夫的话涉及到他和他的船,渔夫一定没说错。渔夫A说:只有我的船、s、h这三艘船有无线电。渔夫B说:K拥有s和h其中一艘船。渔夫K说:h是A的。渔夫D说:他拥有s和d其中一艘船。(?)编程题:1.&nbsp;栈&nbsp;AC2.&nbsp;编辑距离&nbsp;AC3.&nbsp;并查集&nbsp;AC4.&nbsp;图BFS&nbsp;会做但来不及做。输入的矩阵好难处理。#牛客AI配图神器#
查看7道真题和解析 投递深信服等公司7个岗位 软件开发笔面经
点赞 评论 收藏
分享
评论
3
15
分享

创作者周榜

更多
牛客网
牛客企业服务