http://acm.pku.edu.cn/JudgeOnline/problem?id=3650 原题
简单题
- import java.io.*;
- import java.util.*;
- public class Main
- {
- static HashMap<String,String> code;
- public static void main(String[] args) throws Exception
- {
- initMap();
- readFile();
- }
- public static void readFile() throws Exception
- {
- BufferedReader br = new BufferedReader(
- new InputStreamReader(System.in));
- String dest = null;
- while(!(dest=br.readLine()).equals("#"))
- process(dest);
- }
- public static void initMap()
- {
- code = new HashMap<String,String>();
- code.put(" ","%20");
- code.put("!","%21");
- code.put("$","%24");
- code.put("%","%25");
- code.put("(","%28");
- code.put(")","%29");
- code.put("!","%21");
- code.put("*","%2a");
- }
- public static void process(String dest)
- {
- StringBuffer ret = new StringBuffer();
- String temp = null;
- String temp2 = null;
- for(int i=0; i<dest.length(); i++)
- {
- temp = dest.charAt(i)+"";
- if((temp2=code.get(temp))==null)
- {
- ret.append(temp);
- }
- else
- {
- ret.append(temp2);
- }
- }
- System.out.println(ret.toString());
- }
- }