2022 Spring 360 Written Exam Review - R&D Paper E

发表于 2022-03-19 20:00 662 字 4 min read

cos avatar

cos

FE / ACG / 手工 / 深色模式强迫症 / INFP / 兴趣广泛养两只猫的老宅女 / remote

文章整理了360研发E卷前端笔试题,包含30道选择题(涵盖数据库、高数等偏题)和两道编程题。编程题1为强密码验证,用正则或遍历实现;编程题2为堆积货物问题,通过枚举因数和剪枝求解最坏情况下的被盗体积。

This article has been machine-translated from Chinese. The translation may contain inaccuracies or awkward phrasing. If in doubt, please refer to the original Chinese version.

360 written exam review - R&D Paper E, a frontend development written exam including 30 multiple-choice questions and two programming problems.

Multiple Choice (30 questions)

Covered everything — databases, calculus, equations, with more frontend questions in the second half.

Programming Problem 1 - Strong Password Validation (Easy)

Requirements roughly:

  • Password length must be 8 or more
  • Must contain digits, uppercase letters, lowercase letters, and special characters (all four required)

Sample Input

12_Aaqq12
Password123
PASSWORD_123
PaSS^word
12_Aaqq

Sample Output

Ok
Irregular password
Irregular password
Irregular password
Irregular password

Approach

In JS you could just write a regex, but I’m not great with regex… So I just iterated through once and checked. No issues, passed on first try. Very simple and brute force (kids, don’t learn from me).

Code

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
string str;
bool judge(string s) {
    int len = s.length();
    if(len < 8) return false;
    bool flag[4];   // 有数字
    memset(flag, false, sizeof(flag));
    int cnt = 0;
    for(int i = 0; i < len; ++i) {
        if(s[i] >= 'A' && s[i] <= 'Z') {
            if(!flag[0]) {
                flag[0] = true;
                ++cnt;
            }
        } else if(s[i] >= 'a' && s[i] <= 'z') {
            if(!flag[1]) {
                flag[1] = true;
                ++cnt;
            }
        } else if(s[i] >= '0' && s[i] <= '9') {
            if(!flag[2]) {
                flag[2] = true;
                ++cnt;
            }
        } else if(!flag[3]) {   // 特殊字符
            flag[3] = true;
            ++cnt;
        }
        if(cnt == 4) return true;
    }
    return false;
}
int main() {
    while(cin >> str) {
        if(judge(str)) cout << "Ok" << endl;
        else cout << "Irregular password" << endl;
    }
    return 0;
}

Programming Problem 2 - Stacking Goods (Web)

The idea is: originally there are RCL goods stacked into a rectangular box. A thief stole some, leaving (R-2)(C-1)(L-2). Given the current total number of goods, calculate the worst-case number of stolen goods and output that maximum value.

Input Description Input is a number n, representing (R-2)(C-1)(L-2) from the problem.

Output Description Output a number representing the worst-case number of stolen goods.

Sample Input

4

Sample Output

41

Hint For 100% of data: 1 <= n <= 10^9 Sample explanation: R=3, C=5, L=3, 3*5*3-(3-2)*(5-1)*(3-2)=41

Analysis

3 2 3 = 18 1 1 1 = 1 Stolen: 17 4 2 5 = 40 2 1 3 = 6 Stolen: 34

Three rectangular boxes stolen, volume stolen is 1*(R+2)*(L+2)+ 2*R*C +2*(R+2)*C (This can probably be derived mathematically, but my brute force with pruning also got AC 100%) My brute force approach: let r, l, c be the dimensions after theft. R = r+2, L = l+2, C = c+1. Clearly r, c, l must all be factors of n. Factorize n and store all factors in m, iterate through m to get each r, l, c, with some pruning along the way — skip when the product of the first two numbers already exceeds n.

Code

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
int n;
ll ans;
vector<ll> m;
int main() {
    cin >> n;
    int k = sqrt(n);
    for(int i = 1; i <= k; ++i) {
        if(n % i == 0) {
            m.push_back(i);
            m.push_back(n/i);
        }
    }
    sort(m.begin(), m.end());
    int len = m.size();
    for(int r = 0; r < len; ++r) {
        for(int l = 0; l < len; ++l) {
            ll t = m[r]*m[l];
            if(t > n) continue; // 剪枝
            for(int c = 0; c < len; ++c) {
                ll nown = t*m[c];
                if(nown != n) continue;
                ll R = m[r]+2;
                ll L = m[l]+1;
                ll C = m[c]+2;
                ll stole = ll(R*L*C) - nown;
                ans = max(ans, stole);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

喜欢的话,留下你的评论吧~

© 2020 - 2026 cos @cosine
Powered by theme astro-koharu · Inspired by Shoka