zoj 2932 The Seven Percent Solution

The Seven Percent Solution


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 using namespace std;
 5
 6 void judge(char c){
 7     switch(c){
 8         case ‘ ‘: cout << "%20"; break;
 9         case ‘!‘: cout << "%21"; break;
10         case ‘$‘: cout << "%24"; break;
11         case ‘%‘: cout << "%25"; break;
12         case ‘(‘: cout << "%28"; break;
13         case ‘)‘: cout << "%29"; break;
14         case ‘*‘: cout << "%2a"; break;
15         default: cout << c; break;
16     }
17 }
18
19 int main(){
20     string s;
21     while(getline(cin, s)){
22         if(s[0] == ‘#‘)
23             break;
24         int len = s.length();
25         for(int i = 0; i < len; i++)
26             judge(s[i]);
27         cout << endl;
28     }
29     //system("pause");
30     return 0;
31 }
 
时间: 2024-08-07 04:33:39

zoj 2932 The Seven Percent Solution的相关文章

(HDUStep 1.2.5)The Seven Percent Solution(字符串的替换)

题目: The Seven Percent Solution Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2637 Accepted Submission(s): 1562   Problem Description Uniform Resource Identifiers (or URIs) are strings like http:

POJ 3650 &amp; ZJU 2932 &amp; 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

题目1.2.4 The Seven Percent Solution(C++)

Problem 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

HDUOJ 2560 The Seven Percent Solution

#include<iostream> #include<stdlib.h> using namespace std; int main() { //第一个循环用于输入,遇到#停止 while (1) { //第二个循环用于单次输入的每个字符的判断 while (1) { char c; c = getchar(); //若遇到换行符,则结束此次输入 if (c == '\n' || c == EOF) { cout << endl; break; } //遇到#停止 i

HustOJ - 1029

1 #include<iostream> 2 #include<string> 3 using namespace std; 4 int main() 5 { 6 int i=0; 7 string s; 8 while(getline(cin,s)) 9 { 10 if (s[0]=='#') break; 11 else 12 { 13 for (i=0;i<s.size();i++) 14 { 15 if (s[i]==' ') cout<<"%2

【转】100本最棒的英文侦探小说

阅读计划2:100本最棒的英文侦探小说2010-08-15 13:21:28The Top 100 Crime Novels of All Time The Top 100 Crime Novels of All Time is a list published in book form in 1990 by the British-based Crime Writers' Association. Five years later, the Mystery Writers of America

美国100部推理小说排行榜

这份书单是美国推理作家协会(The Mystery Writers of America,简称MWA)票选出来的史上最经典的一百部推理小说排行榜.评选过程极为复杂,首先由推理协会选出本格派.硬汉派.惊悚派.间谍小说等推理小说十个主要流派的十个代表作家,再由这十个作家选出各流派的十部代表作品,然后由协会会员投票排出名次.所以这份书单不仅仅有总的一百强排行榜,还有各个不同流派的十大杰作排名,其中本格和硬汉两派由于名作数量远远超出其它各派,所以都各排了二十部作品. 后来美国出了一本书<The Crow

ZOJ Monthly, March 2018 Solution

A - Easy Number Game 水. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define ll long long 5 #define N 100010 6 ll arr[N]; 7 int n, m; 8 9 int main() 10 { 11 int t; scanf("%d", &t); 12 while (t--) 13 { 14 scanf("%d%d"

ZOJ Monthly, January 2018 Solution

A - Candy Game 水. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 1010 5 int t, n; 6 int a[N], b[N]; 7 8 int main() 9 { 10 scanf("%d", &t); 11 while (t--) 12 { 13 scanf("%d", &n); 14 for (int i = 1; i <