Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <string>
- using namespace std;
- // if string 's' contains symbol for which 'cond_func' returns true
- bool is_in_string(const string& s, int(*cond_func)(int)) {
- auto it = find_if(s.begin(), s.end(),
- [&](const char ch) {return cond_func(ch); });
- return it != s.end();
- }
- // if char 'ch' is not alphanumeric
- int is_not_alnum(int ch) {
- return !isalnum(ch);
- }
- bool is_password_correct(const string& password) {
- // if all symbols are ASCII [33:126]
- for (const auto& ch : password) {
- if (ch < 33 || ch > 126) {
- return false;
- }
- }
- // if length of password is [8:14]
- if (!(password.length() >= 8 && password.length() <= 14)) {
- return false;
- }
- // check for >=3 of 4 classes (uppercase, lowercase, digit, other symbols)
- int class_cnt = 0;
- class_cnt += is_in_string(password, isupper);
- class_cnt += is_in_string(password, islower);
- class_cnt += is_in_string(password, isdigit);
- class_cnt += is_in_string(password, is_not_alnum);
- return class_cnt >= 3;
- }
- int main() {
- string password;
- getline(cin, password);
- cout << (is_password_correct(password) ? "YES" : "NO") << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement