「HD_ACM」The Seven Percent Solution
来源:互联网 发布:《算法》和算法导论 编辑:程序博客网 时间:2024/06/05 06:59
Problem Description
Uniform 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.
->统一资源标识符(uri)字符串像http://icpc.baylor.edu/icpc/,mailto:foo@bar.org,ftp://127.0.0.1/pub/linux,或者只是readme。三种用于确定一个资源,通常在互联网上或本地计算机。某些字符保留在uri,如果保留字符是一个标识符的一部分,那么它必须被代之以百分之一percent-encoded签署两个十六进制数字代表字符的ASCII代码。表七保留字符及其编码如下所示。你的工作是编写一个程序,可以percent-encode一个字符串的字符。
Character Encoding
" " (space) %20
"!" (exclamation point) %21
"$" (dollar sign) %24
"%" (percent sign) %25
"(" (left parenthesis) %28
")" (right parenthesis) %29
"*" (asterisk) %2a
->统一资源标识符(uri)字符串像http://icpc.baylor.edu/icpc/,mailto:foo@bar.org,ftp://127.0.0.1/pub/linux,或者只是readme。三种用于确定一个资源,通常在互联网上或本地计算机。某些字符保留在uri,如果保留字符是一个标识符的一部分,那么它必须被代之以百分之一percent-encoded签署两个十六进制数字代表字符的ASCII代码。表七保留字符及其编码如下所示。你的工作是编写一个程序,可以percent-encode一个字符串的字符。
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 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 spaces, but not at the beginning or end of the string, and there will never be two or more consecutive spaces.
->输入由一个或多个字符串,每个1 - 79个字符长,线路上,紧随其后的是一行只包含“#”结束的信号输入。只使用“#”字符作为end-of-input标记和不会出现任何输入。字符串可以包含空格,但不是在字符串的开头或结尾,也永远不会是两个或两个以上的连续空间。
Output
For 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 "A").
->对于每一个输入字符串,取代保留字符的每一个出现在上面的表中百分比编码,如下所示,输出结果的字符串行本身。注意,星号是% 2的百分比编码(小写字母“a”)而不是% 2(用大写字母“a”)。
题目公析
代码分析
#include <stdio.h>#include <stdlib.h>int main(){int i=0;char a;char str[100];while((a=getchar()) != '#'){switch(a){case ' ': str[i++]='%'; str[i++]='2'; str[i++]='0'; break;case '!': str[i++]='%'; str[i++]='2'; str[i++]='1'; break;case '$': str[i++]='%'; str[i++]='2'; str[i++]='4'; break;case '%': str[i++]='%'; str[i++]='2'; str[i++]='5'; break;case '(': str[i++]='%'; str[i++]='2'; str[i++]='8'; break;case ')': str[i++]='%'; str[i++]='2'; str[i++]='9'; break;case '*': str[i++]='%'; str[i++]='2'; str[i++]='a'; break;case '\n': str[i]='\0'; i=0; printf("%s\n" , str); break;default: str[i++]=a;}}return 0;}
0 0
- 「HD_ACM」The Seven Percent Solution
- the seven percent solution
- The Seven Percent Solution
- The Seven Percent Solution
- The Seven Percent Solution
- The Seven Percent Solution
- The Seven Percent Solution
- 1530. The Seven Percent Solution
- Sicily1530 The Seven Percent Solution
- HDU2719:The Seven Percent Solution
- POJ3650----The Seven Percent Solution
- HDU_OJ-The Seven Percent Solution
- HDU The Seven Percent Solution
- zoj 2932 The Seven Percent Solution
- poj 3650 The Seven Percent Solution
- poj 3650 The Seven Percent Solution
- ZOJ 2932 The Seven Percent Solution
- hd 2719 The Seven Percent Solution
- gdb调试
- HDU-1086 You can Solve a Geometry Problem too
- malloc和 calloc的区别
- 01:台风
- 卡特兰数
- 「HD_ACM」The Seven Percent Solution
- 如何把事情做到最好读书笔记5
- Heritrix1.14源码分析(2) 配置文件order.xml介绍
- Linux netstat命令详解(转)
- 如何把事情做到最好读书笔记6
- Heritrix1.14源码分析(3) 修改配置文件order.xml加快你的抓取速度
- 【Qt编程】基于Qt的词典开发系列<七>--调用网络API
- 滑动tab
- 设计模式C++学习笔记之十二(Command命令模式)