โจทย์
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
รหัสผ่านต้องผ่านหลายเงื่อนไขอิสระพร้อมกัน
คำใบ้ 2
ติดตามไปว่าพบตัวพิมพ์ใหญ่ ตัวพิมพ์เล็ก และตัวเลขหรือยังระหว่างตรวจความยาว
คำใบ้ 3
สตริงว่างหรือสตริงสั้นจะไม่ผ่านทันที แม้จะมีตัวอักษรหลากหลาย
ความซับซ้อนที่คาดหวัง
เวลา O(n), หน่วยความจำเพิ่ม O(1)
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน