Under construction

Still being built. Things may change

URLs

Interview

Time limit1sMemory limit128 MB

Summary
Parse each URL into protocol, host, optional port, and optional path, printing <default> for missing components.
Level

Easy3 of 10

Topics
String, Implementation, Simulation, Brute force
Solved
No attempts yet

Problem

In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the WWW simply consists of all the pretty (or not so pretty) HTML pages that you can read with your web browser. But back then, one of the main intentions behind the design of the WWW was to unify several existing communication protocols.

Then (and even now), information on the Internet was available through a multitude of channels: FTP, HTTP, e-mail, news, Gopher, and many more. Thanks to the WWW, all these services can now be addressed uniformly through URLs (Uniform Resource Locators). For this problem we consider a simplified version of the URL syntax, which is as follows.

<protocol>://<host>[:<port>][/<path>]

The square brackets [ ] mean that the enclosed string is optional and may or may not appear. Some examples of URLs are:

http://www.informatik.uni-ulm.de/acm
ftp://acm.baylor.edu:1234/pub/staff/mr-p
gopher://veryold.edu

More specifically:

  • <protocol> is always one of http, ftp, or gopher.
  • <host> is a string of alphabetic (a-z, A-Z) or numeric (0-9) characters, dots (.), dashes (-), and underscores (_).
  • <port> is a positive integer smaller than 65536.
  • <path> is a string that contains no spaces.

Write a program that parses a URL into its components.

Gopher is an ancestor of today's WWW. It is now nearly extinct, but it was quite important when the WWW was invented.

Input

The first line contains a single integer nn, the number of URLs. Each of the following nn lines contains one URL in the format described above. Each URL consists of at most 60 characters.

Output

For each URL, first print its number in the form URL #k (the first URL is URL #1). Then print four lines giving the protocol, host, port, and path, labelled Protocol, Host, Port, and Path. If the port and/or path are not given in the URL, print the string <default> instead of that value.

Each label is left-justified in a field of width 8 and joined to its value with =. Separate the output blocks of two consecutive URLs with a single blank line; the output ends with a trailing newline and no extra blank line. Follow the exact format shown in the examples below.

Examples3

  1. Example 1

    Input
    3
    ftp://acm.baylor.edu:1234/pub/staff/mr-p
    http://www.informatik.uni-ulm.de/acm
    gopher://veryold.edu
    
    Expected output
    URL #1
    Protocol = ftp
    Host     = acm.baylor.edu
    Port     = 1234
    Path     = pub/staff/mr-p
    
    URL #2
    Protocol = http
    Host     = www.informatik.uni-ulm.de
    Port     = <default>
    Path     = acm
    
    URL #3
    Protocol = gopher
    Host     = veryold.edu
    Port     = <default>
    Path     = <default>
    
  2. Example 2

    Input
    1
    http://www.example.com:8080/index.html
    
    Expected output
    URL #1
    Protocol = http
    Host     = www.example.com
    Port     = 8080
    Path     = index.html
    
  3. Example 3

    Input
    1
    gopher://host.edu
    
    Expected output
    URL #1
    Protocol = gopher
    Host     = host.edu
    Port     = <default>
    Path     = <default>