The seven percent solution

Source: Internet
Author: User
The seven percent solution
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 466 accepted submission (s): 307
problem descriptionuniform resource identifiers (or URIs) are strings like http://icpc.baylor.edu/icpc/, mailto: foo@bar.org, ftp: // 127.0.0.1/pub/Linux, or even just readme.txt that are used to identify a resource, usually on the Internet or a local computer. certain characters are reserved within Uris, and if a reserved character is part of an identifier then it must be Percent-encoded by replacing it with a percent sign followed by two hexadecimal digits representing the ASCII code of the 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

Inputthe input consists of one or more strings, each 1-79 characters long and on a line by itself, followed by a line containing only "#" that signals the end of the input. the character "#" is used only as an end-of-input marker and will not appear anywhere else in the input. A string may contain in spaces, but not at the beginning or end of the string, and there will never be two or more consecutive spaces.
Outputfor each input string, replace every occurrence of a reserved character in the Table above by its percent-encoding, exactly as shown, and output the resulting string on a line by itself. note that the percent-encoding for an asterisk is % 2a (with a lowercase "A") rather than % 2a (with an uppercase "").
Sample Input
Happy 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% 20 Solution
 # Include <iostream> # include "stdio. H" # include "string. H"  Using namespace STD ;  Int  Main  (){  Char C[  1000  ];  While  ( Gets ( C )){  If  ( C [  0  ] = '#'  )  Break  ;  For  (  Int I =  0  ; I < Strlen ( C); I ++ ){  If  ( C [ I ] =  ''  ) Cout <  "% 20"  ; Else if  ( C [ I ] =  '! '  ) Cout <  "% 21"  ;  Else if  ( C[ I ] =  '$'  ) Cout <  "% 24"  ;  Else if  ( C [ I ] =  '%' ) Cout <  "% 25"  ;  Else if  ( C [ I ] =  '('  ) Cout < "% 28"  ;  Else if  ( C [ I ] =  ')'  ) Cout <  "% 29"  ; Else if  ( C [ I ] =  '*'  ) Cout <  "% 2a"  ;  Else Cout < C[ I ];} Cout < Endl ;}  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.