簡単 4件解決済み 正答率57.1%

Password Rules Check

Check a password against simple strength rules.

このチャレンジで学べること

  • Check several rules on one string
  • Use flags for digits and letters
  • Return a clear true or false result

問題

翻訳を表示

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

例

例 1
入力:
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.

例 2
入力:
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用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 LMLaura Mahlow Python 932 ms - 4/5 コードを見る
2 HJhettory Jurash Python 957 ms - 4/5 コードを見る
3 RCRiccardo Corti Python 966 ms - 4/5 コードを見る
4 ゼゼロダニ Java 3,552 ms - 5/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意: この下に解答が4件あります まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。