#C14791. Extract Domain Names
Extract Domain Names
Extract Domain Names
You are given a list of URLs each in the format http://www.example.com
or https://www.example.com
. Your task is to extract and output the domain names from these URLs. If the URL's network location part starts with www.
, it must be removed. Otherwise, the domain name remains unchanged.
For example, given the URLs http://www.example.com
and https://www.test.com
, the output should be example.com
and test.com
respectively.
The formulas in this problem are straightforward: For any URL, if its domain can be represented as www.X, then the answer is X. In LaTeX, one might express this simply as: \(\text{domain} = \begin{cases} X & \text{if } \text{domain} = \texttt{www.}X \\ \text{domain} & \text{otherwise} \end{cases}\).
inputFormat
The input is provided via standard input (stdin) in the following format:
- The first line contains an integer n denoting the number of URLs.
- The next n lines each contain a URL string.
outputFormat
For each provided URL, print the extracted domain name on a new line to standard output (stdout).
## sample2
http://www.example.com
http://www.test.com
example.com
test.com
</p>