HDOJ/HDU 2140 Michael Scofield's letter(字符转换~)

简介: Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won’t be found b...

Problem Description
I believe many people are the fans of prison break. How clever Michael is!! In order that the message won’t be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the heart of Sara. Now can you write a program to help Sara encode the letter from Michael easily?
The letter from Michael every time is a string of lowercase letters. You should encode letters as the rules below:
b is ’ ‘, q is ‘,’, t is ‘!’, m is l, i is e, c is a, a is c, e is i, l is m. It is interesting. Are you found that it is just change michael to leahcim?

Input
The input will consist of several cases, one per line.
Each case is a letter from Michael, the letteres won’t exceed 10000.

Output
For each case, output the encode letter one line.

Sample Input
pmicsibforgevibliqbscrct
ebmovibyout

Sample Output
please forgive me, sara!
i love you!


就是输入一行字符串,然后根据b is ‘空格’, q is ‘,’, t is ‘!’, m is l, i is e, c is a, a is c, e is i, l is m.来转换,输出转换之后的字符串!
在这里,我用Map来存储需要转换的字符,然后查找输出。

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Map<Character, Character> map = new HashMap<Character, Character>();
        map.put('b', ' ');
        map.put('q', ',');
        map.put('t', '!');
        map.put('m', 'l');
        map.put('i', 'e');
        map.put('c', 'a');
        map.put('a', 'c');
        map.put('e', 'i');
        map.put('l', 'm');
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str=sc.next();
            for(int i=0;i<str.length();i++){
                if(map.get(str.charAt(i))!=null){
                    System.out.print(map.get(str.charAt(i)));
                }else{
                    System.out.print(str.charAt(i));
                }
            }
            System.out.println();
        }
    }
}
目录
相关文章
|
1月前
|
Java
hdu-4883- (Best Coder) TIANKENG’s restaurant
hdu-4883- (Best Coder) TIANKENG’s restaurant
13 0
|
测试技术
HDU-1847,Good Luck in CET-4 Everybody!(巴什博弈)
HDU-1847,Good Luck in CET-4 Everybody!(巴什博弈)
|
存储
HDOJ/HDU 2140 Michael Scofield's letter(字符转换~)
HDOJ/HDU 2140 Michael Scofield's letter(字符转换~)
72 0
HDOJ/HDU 1161 Eddy's mistakes(大写字母转换成小写字母)
HDOJ/HDU 1161 Eddy's mistakes(大写字母转换成小写字母)
78 0
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
120 0
|
索引
HDOJ/HDU 2567 寻梦(字符串简单处理)
HDOJ/HDU 2567 寻梦(字符串简单处理)
75 0
HDOJ/HDU 1062 Text Reverse(字符串翻转~)
HDOJ/HDU 1062 Text Reverse(字符串翻转~)
105 0
|
安全 数据安全/隐私保护
HDOJ/HDU 1039 Easier Done Than Said?(字符串处理~)
HDOJ/HDU 1039 Easier Done Than Said?(字符串处理~)
90 0
HDOJ 1070 Milk(水题,考英文的)
HDOJ 1070 Milk(水题,考英文的)
95 0
转:肉饼的自白:You&#39;ve got to find what you love
《You've got to find what you love》是乔布斯2005年在斯坦福大学毕业典礼上的演讲,当我第一次看到这个演讲视频的时候,被彻底震住了。回顾自己跌跌撞撞的人生道路,就是一个不断寻找然后坚持自己钟爱事业的过程。
1357 0