POJ 3650:the Seven Percent solution__pku

Source: Internet
Author: User
Tags reserved
The Seven Percent Solution
Time Limit: 1000MS Memory Limit: 65536K
Total submissions: 7684 accepted: 5159

Description

Uniform Resource Identifiers (or URIs) are strings ,  ftp://127.0.0.1/pub/linux, or even just readme.txt that are used to identify a resource, usually on the I Nternet or a local computer. Certain characters are reserved within URIs, and if a reserved character is part of identifier then it must Cent-encoded by replacing it with a percent sign followed by two hexadecimal digits representing the ASCII code of TH e character. A Table of seven reserved characters and their encodings is shown below. Your job is to write a program that can percent-encode a string of characters.

Character Encoding
"" (space) %20
"!" (exclamation point) %21
"$" (dollar sign) %24
"%" (percent sign) %25
"(left parenthesis) %28
")" (right parenthesis) %29
"*" (asterisk) %2a

Input

The input consists of one or more strings, each 1–79 characters long and in a line by itself, followed by a line containin G only "#" which signals the end of the input. The character "#" is used only as a end-of-input marker and won't appear anywhere else in the input. A string may contain spaces, but is not in the beginning or end of the string, and there'll never be two or more consecutiv E spaces.

Output

For each input string, replace every occurrence of a reserved character in the table above from its percent-encoding, exactl Y as shown, and output the resulting string on a line by itself. Note This percent-encoding for a asterisk is%2a (with a lowercase "a") rather than (with a%2a "a").

Sample Input

Happy Joy joy!
http://icpc.baylor.edu/icpc/
Plain_vanilla
(* *)
?
The 7% Solution
#

Sample Output

happy%20joy%20joy%21
http://icpc.baylor.edu/icpc/
plain_vanilla
%28%2a%2a%29
?
The%207%25%20solution

Source mid-central USA 2007 You left, my world is left with rain ...

#include <stdio.h>
#include <string.h>
int main ()
{
    char str[80];
    while (gets (str) && strcmp (str, "#")!= 0)
    {
        int i, len = strlen (str);
        for (i = 0; i < len; i++)
        {
            if (str[i] = = ')
                printf ("%%20");
            else if (str[i] = = '! ')
                printf ("%%21");
            else if (str[i] = = ' $ ')
                printf ("%%24");
            else if (str[i] = = '% ')
                printf ("%%25");
            else if (str[i] = = ' (')
                printf ("%%28");
            else if (str[i] = = ")
                printf ("%%29 ");
            else if (str[i] = = ' * ')
                printf ("%%2a");
            else printf ("%c", Str[i]);
        printf ("\ n");
    }
    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.