POJ 3650:The Seven Percent Solution
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7684 | Accepted: 5159 |
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
Source
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include<stdio.h>
#include <string.h>
int main()
{
char str[80];
while(gets(str) && strcmp(str, "#") != 0)
{
int i, len = strlen(str);
for(i = 0; i < len; i++)
{
if(str[i] == ' ')
printf("%%20");
else if(str[i] == '!')
printf("%%21");
else if(str[i] == '$')
printf("%%24");
else if(str[i] == '%')
printf("%%25");
else if(str[i] == '(')
printf("%%28");
else if(str[i] == ')')
printf("%%29");
else if(str[i] == '*')
printf("%%2a");
else printf("%c",str[i]);
}
printf("\n");
}
return 0;
}
POJ 3650: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 ...
- The Seven Percent Solution
Problem Description Uniform Resource Identifiers (or URIs) are strings like http://icpc.baylor.edu/i ...
- 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 ...
- 【Poj 1832】连环锁
连环锁 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1260 Accepted: 403 Description 许多 ...
- [BZOJ 2287/POJ openjudge1009/Luogu P4141] 消失之物
题面: 传送门:http://poj.openjudge.cn/practice/1009/ Solution DP+DP 首先,我们可以很轻松地求出所有物品都要的情况下的选择方案数,一个简单的满背包 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
随机推荐
- C++暂停黑窗口
C++中采用system("pause");来暂停黑窗口,那么操纵系统就会将窗口暂停,显示“请按任意键继续. . .” 我们用VS执行代码是,若直接按键盘的F5(开始调试),那么窗 ...
- 全国高校绿色计算大赛 预赛第一阶段(Python)
第1关将字符串反转 #!/usr/bin/env python # -*- coding: utf-8 -*- class Task: def inversion(self, str): # **** ...
- [kuangbin带你飞]专题四 最短路练习
对于最短路,我主要使用的就是dijkstra,Floyd,SPFA这三个算法.先来介绍一下这三个算法. 1. dijkstra算法.它适用于边权为正的情况,它是单源最短路,就是从单个源点出发到所有的结 ...
- centos下安装redis(记录其中踩坑的过程)
一.先下载到redis-3.0.4.tar.gz包(本文以3.0.4版本为例) 我将这个包放在/opt目录下,在/opt下并解压这个包 tar -zxvf redis-.tar.gz 然后进入redi ...
- HashMap、ConcurrentHashMap以及HashTable(面试向)
---->HashMap 在java1.7中,hashmap的数据结构是基于数组+链表的结构,即我们比较熟悉的Entry数组,其包含的(key-value)键值对的形式.在多线程环境下,Hash ...
- 零基础入门学习Python(25)--字典:当索引不好用时
知识点 字典属于映射类型. 列表,元祖,字符串等属于序列类型 创建及访问字典 #创建一个字典 >>> dict1 = {'李宁':'一切皆有可能','耐克':'Just do it' ...
- LNMP中PHP服务的配置
PHP(Hypertxt Preprocessor,超文本预处理器)是一种通用的开源脚本语言,发明于1995年,它吸取了C语言.Java语言及Perl语言的很多优点,具有开源.免费.快捷.跨平台性强. ...
- 使用HTML,CSS快速导出数据到Excel
在应用中经常会遇到要从系统或数据库中导出数据平面文件,一般是导出到txt,csv或excel.txt和csv一般用在系统间的数据交换, 而excel一般有较好的显示效果,可以按照一定的模板导出,导出就 ...
- jQuery实现上传进度条效果
效果:(点击上传按钮) See the Pen pjGNJr by moyu (@MoYu1991) on CodePen. html代码: <!DOCTYPE html> <h ...
- Happy Three Friends
Happy Three Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...