小米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; }