TopcoderArchive
Archive
Algorithm problem

URLParser

Problem statement, definition, constraints, and public examples.

Problem Statement

When a web client (like a browser) requests a particular web page, it typically replaces certain characters with escape sequences. For instance, spaces are replaced with "%20". Your task is to reverse this, replacing every escape sequence in the input with the character it represents. Each escape sequence is formatted as "%XX" where XX is the ASCII value of the escaped character in hexadecimal.

Definition

Class:
URLParser
Method:
parse
Parameters:
String
Returns:
String
Method signature:
String parse(String url)
(be sure your method is public)

Constraints

  • url will contain between 1 and 50 characters, inclusive.
  • Each '%' in the input will be followed by a hexadecimal value between 20 (hex) and 7E (letters will be uppercase).
  • Each character in the input will have ASCII value between 32 and 126, inclusive.

Examples

  1. "http://www.%20%40%20%40%20.com/%25"
    Returns: "http://www. @ @ .com/%"
    "%20" is the escape sequence for ' ', while "%40" stands for '@' and "%25" stands for '%'.
  2. "%20%21%22%23%24%25%26%27%28"
    Returns: " !\"#$%&'("
  3. "%48%65%6C%6C%6F%20%57%6F%72%6C%64%21"
    Returns: "Hello World!"
  4. "%2525"
    Returns: "%25"
Back to all problems