POJ 3650 & ZJU 2932 & HDU 2719 The Seven Percent Solution(模拟)

题目链接:

PKU:http://poj.org/problem?id=3650

ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1931

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2719

Description

Uniform Resource Identifiers (or URIs) are strings like http://icpc.baylor.edu/icpc/mailto:[email protected]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

Source

Mid-Central USA 2007

代码如下:

#include <cstdio>
#include <cstring>
int main()
{
    char s[1000];
    while(gets(s))
    {
        int len = strlen(s);
        if(s[0] =='#' && len == 1)
            break;
        for(int i = 0; i < len; i++)
        {

            if(s[i]==' ')
                printf("%%20");
            else if(s[i] == '!')
                printf("%%21");
            else if(s[i] == '$')
                printf("%%24");
            else if(s[i] == '%')
                printf("%%25");
            else if(s[i] == '(')
                printf("%%28");
            else if(s[i] == ')')
                printf("%%29");
            else if(s[i] == '*')
                printf("%%2a");
            else
                printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-10-08 22:51:36

POJ 3650 & ZJU 2932 & HDU 2719 The Seven Percent Solution(模拟)的相关文章

POJ 3654 &amp; ZOJ 2936 &amp; HDU 2723 Electronic Document Security(模拟)

题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2936 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2723 Description The Tyrell corporation uses a state-of-the-art electronic document system th

POJ 2135 Farm Tour &amp;&amp; HDU 2686 Matrix &amp;&amp; HDU 3376 Matrix Again 费用流求来回最短路

累了就要写题解,最近总是被虐到没脾气. 来回最短路问题貌似也可以用DP来搞,不过拿费用流还是很方便的. 可以转化成求满流为2 的最小花费.一般做法为拆点,对于 i 拆为2*i 和 2*i+1,然后连一条流量为1(花费根据题意来定) 的边来控制每个点只能通过一次. 额外添加source和sink来控制满流为2. 代码都雷同,以HDU3376为例. #include <algorithm> #include <iostream> #include <cstring> #in

POJ 2777 &amp;&amp; ZOJ 1610 &amp;&amp;HDU 1698 --线段树--区间更新

直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 -- 区间更新的话 分为 增减 或者 修改 主要就是个 laze 标记 就是延迟更新 对于区间更新的写法 一般是有2种 其一 仔细划分到每个细小的区间    另一 粗略划分 反正 ==我的代码里会给出2种写法 看自己喜好 hdu 1 //线段树 成段更新 ---> 替换 根结点的查询 2 3 #i

HDU 3623 Best Cow Line, Gold(模拟,注意思路,简单)

题目 POJ 3617 和 这道题题目一样,只是范围稍稍再小一点. //模拟试试 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; char s[30010][2]; bool bijiao(int st,int ed) { if(st==ed) return true; if(s[st][0]<s[ed][0]) return true; else if(s

hdu 5640 King&#39;s Cake(模拟)

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

hdu 4930 Fighting the Landlords (模拟)

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 52 Problem Description Fighting the Landlords is a card game which has been a heat for ye

hdu 4891 The Great Pan (模拟)

为什么要开__int64 巨巨在哪~ # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int main () { __int64 count; int i,len,cot,cot1,j,flag,n; char a[1001][1030]; while(~scanf("%d",&n)) { getchar(); flag=0

HDU 4930 Fighting the Landlords(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 解题报告:斗地主,加了一个四张可以带两张不一样的牌,也可以带一对,判断打出一手牌之后,如果对手没有能够大过你的牌就输出Yes,或者如果你把手上的牌一次性打完也输出Yes,否则输出No,代码有280多行,表示光是敲代码就花了一个多小时,手速还是太慢. 1.首先判断手上的牌能不能一次打完 如果一次性打不完: 2.首先判断对方有没有一对王,有就输出No 3.判断对手有没有四张的牌,如果有,再判断自己

2014多校第三场1005 || HDU 4891 The Great Pan(模拟)

题目链接 题意 : 给你n行字符串,问你有多少种理解方式.有两大类的理解 (1){A|B|C|D|...}代表着理解方式可以是A,可以是B或C或者D. (2)$blah blah$,在$$这两个符号中间,如果是不连续的空格的那个位置就有2种理解方式,可以理解为没有空格也可以理解为有空格.如果有连续N个空格的位置,那里就有N+1种理解方式. 最后所有的理解方式相乘,数据保证$一定与$匹配,{一定与匹配},不会有任何嵌套,类似{$$}或者{{}}或者${}$这种情况都不会出现,也不会有{$}这种情况