【杭电-oj】-2719-特定字符转换成非字符
来源:互联网 发布:不好意思网络中断日语 编辑:程序博客网 时间:2024/05/23 18:48
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.
Character Encoding
" " (space) %20
"!" (exclamation point) %21
"$" (dollar sign) %24
"%" (percent sign) %25
"(" (left parenthesis) %28
")" (right parenthesis) %29
"*" (asterisk) %2a
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.
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").
Sample Input
Happy Joy Joy!http://icpc.baylor.edu/icpc/plain_vanilla(**)?the 7% solution#
Sample Output
Happy%20Joy%20Joy%21http://icpc.baylor.edu/icpc/plain_vanilla%28%2a%2a%29?the%207%25%20solution
#include<stdio.h>#include<string.h>int main(){int l;char a[100];while(gets(a)){if(a[0]=='#')break;l=strlen(a); for(int i=0;i<l;i++){if(a[i]==' ')printf("%%20");<span style="white-space:pre"></span>//遇到直接转换输出else if(a[i]=='!')printf("%%21");else if(a[i]=='$')printf("%%24");else if(a[i]=='%')printf("%%25");else if(a[i]=='(')printf("%%28");else if(a[i]==')')printf("%%29");else if(a[i]=='*')printf("%%2a");elseprintf("%c",a[i]);}printf("\n");}return 0;}
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.
Character Encoding
" " (space) %20
"!" (exclamation point) %21
"$" (dollar sign) %24
"%" (percent sign) %25
"(" (left parenthesis) %28
")" (right parenthesis) %29
"*" (asterisk) %2a
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.
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").
Sample Input
Happy Joy Joy!http://icpc.baylor.edu/icpc/plain_vanilla(**)?the 7% solution#
Sample Output
Happy%20Joy%20Joy%21http://icpc.baylor.edu/icpc/plain_vanilla%28%2a%2a%29?the%207%25%20solution
0 0
- 【杭电-oj】-2719-特定字符转换成非字符
- 【杭电-oj】-3079-字符转换(元音大写,辅音小写)
- 【OJ练习】字符转换
- 去掉字符串中特定字符,然后转换成整型
- 【杭电oj】2719 - The Seven Percent Solution (特殊字符输出)(水)
- 西南科技大学OJ题 数字转换成字符0613
- 九度oj 1049 字符串去特定字符
- 九度OJ 1049 字符串去特定字符
- 九度OJ--1049--字符串去特定字符
- 九度 OJ 1049 字符串去特定字符
- 九度OJ—题目1049:字符串去特定字符
- 九度 OJ 1049:字符串去特定字符
- C 字符串去特定字符(九度OJ 1049)
- 九度oj:题目1049:字符串去特定字符
- 九度OJ-题目1049 字符串去特定字符
- 非中文和中文字符转换成整形的范围
- tolower 把字符转换成小写字母,非字母字符不做出处理
- 杭电 1860 统计字符
- ORMLite完全解析(二)官方文档第二章、如何使用ORMLite
- wifidog 源码初分析(二)
- 第11章评估产品机会——确定待解决的问题
- Hexo博客之旅
- FFmpeg在iOS上完美编译
- 【杭电-oj】-2719-特定字符转换成非字符
- 如何在Windows7(IIS7)环境下安装 PHP-OK
- HDU 1010 Tempter of the Bone dfs 奇偶剪枝
- Java多线程技术之CyclicBarrier
- SAP Basis系统管理中重置用户缓冲哪些需要注意
- 虚拟机深入学习
- Linux下对MySql数据库备份与恢复
- oracle11g单机静默安装
- git设置忽略文件