小米2021校招 软件开发方向

1.
#include <iostream>
#include <string>
using namespace std;
int check(string passwd)
{
    if(passwd.length() > 120 || passwd.length() < 8) return 1;
    bool containDigit = false, containSign = false, containUpper = false, containLower = false;
    for(char c : passwd) {
        if(isdigit(c)) containDigit = true;
        else if(isupper(c)) containUpper = true;
        else if(islower(c)) containLower = true;
        else containSign = true;
    }
    if(containDigit && containSign && containUpper && containLower) return 0;
    return 2;
}
int main() {
    string passwd;
    while(cin >> passwd) {
        cout << check(passwd) << "\n";
    }
    return 0;
}
2.
#include <iostream>
#include <vector>
using namespace std;
bool check(vector<string>& chars, vector<string>& used, string& target, int p, int i, int j)
{
    if(p == target.size()) return true;
    if(i == chars.size() || i < 0 || j == chars[0].size() || j < 0) return false;
    if(used[i][j] == '1') return false;
    if(target[p] != chars[i][j]) return false;
    used[i][j] = '1';
    if(check(chars, used, target, p + 1, i, j + 1)) return true;
    if(check(chars, used, target, p + 1, i, j - 1)) return true;
    if(check(chars, used, target, p + 1, i - 1, j)) return true;
    if(check(chars, used, target, p + 1, i + 1, j)) return true;
    used[i][j] = '0';
    return false;
}
bool solve(vector<string>& chars, string& target)
{
    if(target.empty()) return false;
    vector<string> used{"0000", "0000", "0000", "0000"};
    for(int i = 0; i < chars.size(); ++i) {
        for(int j = 0; j < chars[i].size(); ++j) {
            if(check(chars, used, target, 0, i, j)) return true;
        }
    }
    return false;
}
int main() {
    vector<string> chars {"ABCE", "SFCS", "ADEE"};
    string target; cin >> target;
    bool res = solve(chars, target);
    if(res == true) {
        cout << "true";
    } else {
        cout << "false";
    }
    return 0;
}



#小米##笔试题目#
全部评论

相关推荐

09-02 11:14
已编辑
四川大学 Java
吴offer选手:这种面试是最烦的,学不到东西,然后还被挂的莫名其妙。之前看到一种说法是面试官如果不想要你了,就会问一些很简单的问题,防止你举报他
点赞 评论 收藏
分享
09-19 12:15
门头沟学院 Java
迷茫的大四🐶:这下是真的打牌了,我可以用感谢信和佬一起打牌吗
点赞 评论 收藏
分享
评论
2
4
分享

创作者周榜

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