#C10993. Count Unique Domains from Email Addresses

    ID: 40259 Type: Default 1000ms 256MiB

Count Unique Domains from Email Addresses

Count Unique Domains from Email Addresses

In many data processing tasks, it is often required to count the number of unique domains from a list of email addresses. Here, an email address is in the form (username@domain). Your task is to extract the domain part (i.e., the part after the '@' character) from each email in the given input and then output the number of unique domains.

For example, given the email addresses alice@example.com and bob@example.com, the domain example.com appears twice but should only be counted once. In mathematical terms, if (E = {e_1, e_2, \dots, e_n}) where each (e_i = \text{username}@\text{domain}), then you are to compute (|{ domain : e_i \in E }|), i.e. the cardinality of the set of domains.

inputFormat

The input is read from stdin and is formatted as follows:

(n) — an integer representing the number of email addresses.
Followed by (n) lines, each containing one email address.

Note: (n) can be zero; in that case, the output should be 0.

outputFormat

Print to stdout a single integer — the number of unique domain names extracted from the email addresses.## sample

5
alice@example.com
bob@example.com
charlie@example.org
dave@example.com
eve@example.org
2

</p>