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

 

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%21
http://icpc.baylor.edu/icpc/
plain_vanilla
%28%2a%2a%29
?
the%207%25%20solution
 

#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的更多相关文章

  1. HDUOJ-------2719The Seven Percent Solution

    The Seven Percent Solution Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  2. zoj 2932 The Seven Percent Solution

    The Seven Percent Solution Time Limit: 2 Seconds      Memory Limit: 65536 KB Uniform Resource Identi ...

  3. POJ 3650:The Seven Percent Solution

    The Seven Percent Solution Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7684   Accep ...

  4. HDU 2719 The Seven Percent Solution

    #include <cstdio> #include <cstring> int main() { ]; ]!='#') { ; while (i<strlen(s)) ...

  5. HDU 2719 The Seven Percent Solution (水题。。。)

    题意:把字符串中的一些特殊符号用给定的字符串代替. 析:没的说. 代码如下: #include <iostream> #include <cstdio> #include &l ...

  6. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  7. 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 数据库 ...

  8. Enterprise Solution 开源项目资源汇总 Visual Studio Online 源代码托管 企业管理软件开发框架

    Enterprise Solution 是一套管理软件开发框架,在这个框架基础上开发出一套企业资源计划系统Enterprise Edition. 现将Enterprise Solution开发过程中遇 ...

  9. Windows 10 部署Enterprise Solution 5.5

    Windows 10正式版发布以后,新操作系统带来了许多的变化.现在新购买的电脑安装的系统应该是Windows 10.与当初用户不习惯Windows 7,购买新电脑后第一个想做的事情就是重装成XP,估 ...

随机推荐

  1. Python中特殊函数和表达式lambda,filter,map,reduce

    1.lambda:使用lambda表达式可以定义一个匿名函数 lambda表达式是一种简洁格式的函数.该表达式不是正常的函数结构,而是属于表达式的类型 (1)基本格式: lambda 参数,参数... ...

  2. Ubuntu12.04下Qt连接MySQL数据库

    本文介绍在Ubuntu12.04 (64 bit) 下使用Qt 4.8.2连接MySQL(Ver 14.14 Distrib 5.5.43)数据库. 1.安装 Qt 和 MySQL 若未安装以上软件, ...

  3. EasyUITree设置节点选中

    function callback1(){ reloadMind(); LoadTree0($("); setTimeout(function(){ var node = $('#tt1') ...

  4. Permutations LT46

    Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...

  5. 对团队项目的NABCD的分析

    需求(N):我们的软件是面向广大想记录自己所爱动植物成长点滴的人.目前没有很好地软件,只有手机或者电脑上的笔记本和备忘录. 做法(A):我们的软件可以交流可以节约积累知识的时间,将记录从记事本中摘出来 ...

  6. jQuery学习笔记:基础

    本文主要总结jQuery中一些知识点 概念 美元符号$是著名的jQuery符号.jQuery把所有功能全部封装在一个全局变量jQuery中,而$也是一个合法的变量名,它是变量jQuery的别名 $本质 ...

  7. OneZero第三周第一次站立会议(2016.4.4)

    1. 时间: 13:30--13:45  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  8. Java第14章笔记

    Java 中无参无返回值和带参带返回值习题 编写一个 Java 程序,实现输出学生年龄的最大值 要求: 1. 要求通过定义无参带返回值的方法来实现,返回值为最大年龄 2. 方法中将​学生年龄保存在数组 ...

  9. Java第15章笔记

    字符串的概述 1.什么是字符串:零个或多个字符组成的有限序列 2.如何使用字符串:(使用字符串分为两步)          1)定义并初始化字符串          2)使用字符,对字符串进行一些处理 ...

  10. Java 数组拷贝方法 System.arraycopy

    System类提供的数组拷贝方法: public static native void arraycopy(Object src, int srcPos, Object dest, int destP ...