百度前端暑期实习笔试-3.13

选择题

(终于是正经前端题了),虽然考的都是我不太熟的东西,只能说这题很前端。

编程题(AK)

最后一题稀里糊涂过了,反正就是过了

第一题,计数(忘记c++怎么遍历map了)

#include<bits/stdc++.h>
#include<cstring>
using namespace std;

string str = "Baidu";
int arr[300];

int main() {
    int t;
    cin >> t;
    
    while(t--) {
        string s;
        cin >> s;
        if(s.length() != 5) {
            cout<< "No" << endl;
            continue;
        }    
        for(int i = 0; i < str.size(); i++) {
			arr[(int)str[i]] = 1;
		}
        for(int i = 0; i < s.size(); i++) {
        	arr[(int)s[i]] --;
		}
		int flag = true;
		for(int i = 0; i < str.size(); i++) {
			if(arr[(int)str[i]] == 1) flag = false;
		}
		if(flag) cout<< "Yes" << endl;
		else cout<< "No" << endl;
    }
}

第二题,滑动窗口

#include<bits/stdc++.h>
#include<cstring>
using namespace std;

int a[10010];

struct node {
    int val, cnt;
}b[10010];

int main() {
    int t;
    cin >> t;
    
    while(t--) {
        int n, k;
        scanf("%d%d", &n, &k);
        for(int i = 0 ; i < n; i ++) {
        	scanf("%d", &a[i]);
		}
		sort(a, a + n);
		int cnt = 0;
		memset(b, 0, sizeof(b));
        b[0].val = a[0];
		b[0].cnt = 1;
		for(int i = 1; i < n; i++) {
			if(a[i] == a[i - 1])b[cnt].cnt ++;
			else  {
				b[++cnt].cnt = 1;
                b[cnt].val = a[i];
			}
		}
		
		int tot = 0;
		int l = 0, r = 0;
		while(r < n) {
			while(tot < k && r < n) {
				tot += b[r++].cnt;
			}
			while(tot > k && l < r) {
				tot -= b[l++].cnt;	
			}
			if(tot == k) break;
		}
        if(tot == k) {
        	cout << b[l].val << ' ' << b[r - 1].val << endl;
		} else cout << "-1" << endl; 
    }
}

第三题,暴力?反正过了

#include<bits/stdc++.h>
using namespace std;

int main() {
    int x;
    cin >> x;
    
    int w = 2;
    int cnt = 1;
    while(cnt <= x) {
        printf("r");
        if(cnt + w > x) break;
        cnt += w;
        w ++;
    }
    x -= cnt;
    w = 2;
    cnt = 1;
    while(cnt <= x) {
        printf("e");
        if(cnt + w > x) break;
        cnt += w;
        w ++;
    }
    x -= cnt;
    w = 2;
    cnt = 1;
    while(cnt <= x) {
        printf("d");
        if(cnt + w > x) break;
        cnt += w;
        w ++;
    }
    x -= cnt;
    w = 2;
    cnt = 1;
    while(cnt <= x) {
        printf("r");
        if(cnt + w > x) break;
        cnt += w;
        w ++;
    }
    x -= cnt;
    w = 2;
    cnt = 1;
    while(cnt <= x) {
        printf("e");
        if(cnt + w > x) break;
        cnt += w;
        w ++;
    }
    x -= cnt;
    w = 2;
    cnt = 1;
    while(cnt <= x) {
        printf("d");
        if(cnt + w > x) break;
        cnt += w;
        w ++;
    }
}

#我的实习求职记录##百度笔试##百度##百度前端#
2023年实习面试记录 文章被收录于专栏

记录一下2023年上半年找实习工作的面试情况。

全部评论
后端b卷 最后一题记忆化搜索写了一个多小时0% 心累 早知道退出去看会电视了
2 回复 分享
发布于 2023-03-13 21:13 江苏
选择题虽然基本考的前端知识但还是不会做怎么会记得到这么细啊
1 回复 分享
发布于 2023-03-13 21:13 四川
第三题题目啥意思啊?看了半天没读懂,想法跟案例完全不一样。
点赞 回复 分享
发布于 2023-03-13 21:06 广东
大佬
点赞 回复 分享
发布于 2023-03-13 21:06 北京
再投携程试试,岗位还有很多
点赞 回复 分享
发布于 2023-03-14 19:11 重庆

相关推荐

02-05 08:49
已编辑
武汉大学 Web前端
野猪不是猪🐗:36k和36k之间亦有差距,ms的36k和pdd的36k不是一个概念
点赞 评论 收藏
分享
评论
7
21
分享

创作者周榜

更多
牛客网
牛客企业服务