The Seven Percent Solution
|
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 |
|
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! |
|
Sample Output
Happy%20Joy%20Joy%21 |
#include<stdio.h>
void main()
{
char a[1000];
int n;
while(1)
{
gets(a);
//getchar();
if(a[0]=='#')
return;
for(int j=0;a[j]!='\0';j++);
j++; n=j;
for(int i=0;a[i]!='\0';i++)
{
switch(a[i])
{
case ' ' :
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='0';
i=i+2;
j=n=n+2;
break;
case '!':
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='1';
i=i+2;
j=n=n+2;
break;
case '$':
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='4';
i=i+2;
j=n=n+2;
break;
case '%':
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='5';
i=i+2;
j=n=n+2;
break;
case '(':
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='8';
i=i+2;
j=n=n+2;
break;
case ')':
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='9';
i=i+2;
j=n=n+2;
break;
case '*':
for(;j>i;j--)
a[j+2]=a[j];
a[i]='%';
a[i+1]='2';
a[i+2]='a';
i=i+2;
j=n=n+2;
break;
}
}
printf("%s\n",a);
}
}
The Seven Percent Solution的更多相关文章
- HDUOJ-------2719The Seven Percent Solution
The Seven Percent Solution Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- zoj 2932 The Seven Percent Solution
The Seven Percent Solution Time Limit: 2 Seconds Memory Limit: 65536 KB Uniform Resource Identi ...
- POJ 3650:The Seven Percent Solution
The Seven Percent Solution Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7684 Accep ...
- HDU 2719 The Seven Percent Solution
#include <cstdio> #include <cstring> int main() { ]; ]!='#') { ; while (i<strlen(s)) ...
- HDU 2719 The Seven Percent Solution (水题。。。)
题意:把字符串中的一些特殊符号用给定的字符串代替. 析:没的说. 代码如下: #include <iostream> #include <cstdio> #include &l ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- Enterprise Solution 3.1 企业应用开发框架 .NET ERP/CRM/MIS 开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms
行业:基于数据库的制造行业管理软件,包含ERP.MRP.CRM.MIS.MES等企业管理软件 数据库平台:SQL Server 2005或以上 系统架构:C/S 开发技术 序号 领域 技术 1 数据库 ...
- Enterprise Solution 开源项目资源汇总 Visual Studio Online 源代码托管 企业管理软件开发框架
Enterprise Solution 是一套管理软件开发框架,在这个框架基础上开发出一套企业资源计划系统Enterprise Edition. 现将Enterprise Solution开发过程中遇 ...
- Windows 10 部署Enterprise Solution 5.5
Windows 10正式版发布以后,新操作系统带来了许多的变化.现在新购买的电脑安装的系统应该是Windows 10.与当初用户不习惯Windows 7,购买新电脑后第一个想做的事情就是重装成XP,估 ...
随机推荐
- 基于Confluent.Kafka实现的KafkaConsumer消费者类和KafkaProducer消息生产者类型
一.引言 研究Kafka有一段时间了,略有心得,基于此自己就写了一个Kafka的消费者的类和Kafka消息生产者的类,进行了单元测试和生产环境的测试,还是挺可靠的. 二.源码 话不多说,直接上代码,代 ...
- (转)Eclipse中需要查看某个类的源码,直接按住Ctrl 然后点击想要查看的类或则方法
文章转自:http://blog.sina.com.cn/s/blog_52f623240102vpcr.html 在Eclipse中需要查看某个类的源码,直接按住Ctrl 然后点击想要查看的 ...
- 1F - A+B for Input-Output Practice (III)
Your task is to Calculate a + b. Input Input contains multiple test cases. Each test case contains a ...
- c++计时
一.clock#include<ctime>clock_t start,end;start=clock();end=clock();cout<<start<<',' ...
- 把一行数字(readline)读进List并以科学计数法输出(write)到文件
主要过程是读取的时候是一行字符串,需要Strip去除空格等,然后split变成一个List. 注意这时候数据结构是List但是每一个元素是Str性质的. 所以需要map(float,List) 把这 ...
- Spring 循环引用(二)源码分析
Spring 循环引用(二)源码分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 循环引用相关文章: & ...
- chrome、firefox表单自动提交诱因 -- 非type=hidden的单输入域(input)
开发任务中遇到很费解的一个form自动提交问题,form中只有一个input时回车会触发自动提交表单,当在多一个非type=hidden的input时,又不会出现表单自动提交. 代码示例: 会出现自动 ...
- java面试感悟【一】
我最终选择不包装工作经验,或许是因为我怂,或许是因为一些莫名其妙的坚持…… 然而结果就是在boss上沟通了20多家,只有7家让我投了简历,1家跟我说要我发个时间段给他稍后告诉我面试时间,然后就没有然后 ...
- java基本知识归集
类中可以有几种东西:属性,方法,构造器,初始化块 new创建对象时, 1.类属性和类初始化块分配空间. 2.执行默认初始化 如有父类,先为父类执行父类自己的1和2步骤,再执行上面的1和2. 一个类执行 ...
- IOS初级:UIAlertController
- (IBAction)signOutAction:(id)sender { //初始化,StyleActionSheet是对话框的样式 UIAlertController *alert = [UIA ...