問題
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.
制約
0 ≤ length of password ≤ 100
例
入力:
password = "Secret123"
期待される出力:
expected = True
入力:
std::string password = "Secret123";
期待される出力:
bool expected = true;
入力:
string password = "Secret123";
期待される出力:
bool expected = true;
解説
9 characters with uppercase S, lowercase letters and digits: strong.
入力:
password = "password1"
期待される出力:
expected = False
入力:
std::string password = "password1";
期待される出力:
bool expected = false;
入力:
string password = "password1";
期待される出力:
bool expected = false;
解説
There is no uppercase letter, so it is not strong.
解き方のヒント
まずは自分で考えてから、ヒントを1つずつ開いてみましょう。
ヒント 1
The password must satisfy several independent conditions at once.
ヒント 2
Track whether you have seen an uppercase letter, a lowercase letter, and a digit while checking length.
ヒント 3
An empty string or short string fails immediately even if it contains mixed characters.
目安の計算量
O(n) time, O(1) extra space
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。