Đề bài
A password is strong if it has at least 8 characters, at least one uppercase letter, at least one lowercase letter and at least one digit (English letters and 0–9).
Implement is_strong_password(password).
Input
password: The password to check (ASCII characters).
Output
Return true if all rules hold, otherwise false.
Ràng buộc
0 ≤ length of password ≤ 100
Ví dụ
Đầu vào:
password = "Secret123"
Kết quả mong đợi:
expected = True
Đầu vào:
std::string password = "Secret123";
Kết quả mong đợi:
bool expected = true;
Đầu vào:
string password = "Secret123";
Kết quả mong đợi:
bool expected = true;
Giải thích
9 characters with uppercase S, lowercase letters and digits: strong.
Đầu vào:
password = "password1"
Kết quả mong đợi:
expected = False
Đầu vào:
std::string password = "password1";
Kết quả mong đợi:
bool expected = false;
Đầu vào:
string password = "password1";
Kết quả mong đợi:
bool expected = false;
Giải thích
There is no uppercase letter, so it is not strong.
Hướng tiếp cận
Hãy tự thử trước, sau đó mở từng gợi ý một.
Gợi ý 1
The password must satisfy several independent conditions at once.
Gợi ý 2
Track whether you have seen an uppercase letter, a lowercase letter, and a digit while checking length.
Gợi ý 3
An empty string or short string fails immediately even if it contains mixed characters.
Độ phức tạp mong đợi
O(n) time, O(1) extra space
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.