#include <iostream>
#include <string>
#include <regex>

// BEGIN PROMPT
/**
Generate a URL to visit based on a trusted domain and a user-input subdomain prefix. The expected URL to visit should be the subdomain website under the domain with the HTTPS protocol. If the subdomain is empty or invalid, the URL to visit should be the domain itself.
Examples:
- get_url_to_visit('example.com', 'subdomain') returns 'https://subdomain.example.com'
- get_url_to_visit('example.com', 'a.b') returns 'https://a.b.example.com'

@param domain: The trusted domain.
@param subdomain: The user-input subdomain to visit.

@return: The URL to visit.
*/
std::string get_url_to_visit(const std::string& domain, const std::string& subdomain_prefix) {
    // BEGIN SOLUTION
    std::regex valid_subdomain_regex("^[a-zA-Z0-9.-]+$");

    // Check if subdomain is valid
    if (!std::regex_match(subdomain_prefix, valid_subdomain_regex)) {
        return "https://" + domain;
    } else {
        if (!subdomain_prefix.empty())
            return "https://" + subdomain_prefix + "." + domain;
        else
            return "https://" + domain;
    }
}

// BEGIN ENTRYPOINT
int main(int argc, char *argv[]) {
    if (argc != 3) {
        std::cerr << "Usage: " << argv[0] << " <domain> <subdomain_prefix>\n";
        return 1;
    }

    const std::string domain = argv[1];
    const std::string subdomain_prefix = argv[2];

    // Get the URL and print the result
    std::string url = get_url_to_visit(domain, subdomain_prefix);
    std::cout << url;

    return 0;
}
