Preview:
#include <iostream>
#include <string>
#include <set>

using namespace std;

int minimumNumber(int n, const string& password) {
    // Define character sets
    const string numbers = "0123456789";
    const string lower_case = "abcdefghijklmnopqrstuvwxyz";
    const string upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const string special_characters = "!@#$%^&*()-+";

    // Flags to check the presence of required character types
    bool has_digit = false;
    bool has_lower = false;
    bool has_upper = false;
    bool has_special = false;

    // Check for each character in the password
    for (char ch : password) {
        if (numbers.find(ch) != string::npos) has_digit = true;
        else if (lower_case.find(ch) != string::npos) has_lower = true;
        else if (upper_case.find(ch) != string::npos) has_upper = true;
        else if (special_characters.find(ch) != string::npos) has_special = true;
    }

    // Count how many character types are missing
    int missing_types = 0;
    if (!has_digit) missing_types++;
    if (!has_lower) missing_types++;
    if (!has_upper) missing_types++;
    if (!has_special) missing_types++;

    // Calculate the total number of characters needed
    int total_needed = max(6 - n, 0); // Length requirement
    return max(missing_types, total_needed);
}

int main() {
    int n;
    cin >> n; // Length of the password
    string password;
    cin >> password; // The password string

    int result = minimumNumber(n, password);
    cout << result << endl; // Output the minimum number of characters to add

    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter