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 InputHappy Joy! Http://icpc.baylor.edu/icpc/plain_vanilla (**)? The 7% solution # |
Sample outputHappy % 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 ;}