Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isextra(char c) {return !isalnum(c);}
- int main() {
- // ios_base::sync_with_stdio(0), cin.tie(0);
- int N; cin >> N, cin.ignore();
- int cnt_0 = 0;
- vector<pair<int, string>> pwd(N, {0, ""});
- for (auto &[score, pass] : pwd) {
- getline(cin, pass);
- // cerr << "\"" << pass << "\"" << "\n";
- /// rule 1: |pass| >= 4 and no space ///
- if ((int)pass.size() < 4 or pass.find(' ') != string::npos) {++cnt_0; continue;}
- /// rule 2: score += 2 * max(|pass| - 8, 0) + 10 ///
- score += 2 * max((int)pass.size() - 8, 0) + 10;
- // cerr << "r2: " << score << "\n";
- int cnt_upper = 0, cnt_lower = 0, cnt_digit = 0, cnt_extra = 0;
- for (char c : pass) cnt_upper += isupper(c), cnt_lower += islower(c), cnt_digit += isdigit(c), cnt_extra += isextra(c);
- /// rule 3: score -= 6 if cnt_extra < 3 ///
- if (cnt_extra < 3) score -= 6;
- /// rule 4: type = {upper, lower, digit}, score += 2 with each type found ///
- score += 2 * (!!cnt_upper + !!cnt_lower + !!cnt_digit);
- /// rule 5: score += 10 * floor(cnt_extra / 5) ///
- score += 10 * (cnt_extra / 5);
- // cerr << "r5: " << score << "\n";
- /// rule 6: each alternate {alpha, digit, extra} let score += 2 ///
- char flag_rule_6 = pass[0];
- for (char &c : pass) {
- if (
- (isalpha(c) and !isalpha(flag_rule_6))
- or (isdigit(c) and !isdigit(flag_rule_6))
- or (isextra(c) and !isextra(flag_rule_6))
- ) score += 2;
- flag_rule_6 = c;
- }
- // cerr << "r6: " << score << "\n";
- }
- sort(pwd.rbegin(), pwd.rend());
- cout << cnt_0 << "\n";
- for (int i = 0; i < N-cnt_0; ++i) {
- cout << pwd[i].first << " " << pwd[i].second << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement