天天看点

HDU 1075 What Are You Talking About(java版)

题目:http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=12557&pid=1004&ojid=0

类型:字典树或map

map解

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

public class Main {
    public static void main(String[] args)  {
        Scanner kb = new Scanner(System.in);
        boolean pd=false;
        Map<String, String> map=new HashMap<>();
        kb.next();
        String str1=kb.next();
        String str2;
        while(!str1.equals("END")) {
            str2=kb.next();
            map.put(str2, str1);
            str1=kb.next();
        }
        kb.next();
        kb.nextLine();
        str1=kb.nextLine();
        while(!str1.equals("END")) {
            String str="";
            int i=-;
            while(i<str1.length()-) {
                i++;
                while((str1.charAt(i)>='a'&&str1.charAt(i)<='z')||(str1.charAt(i)>='A'&&str1.charAt(i)<='z'))
                {
                    str+=str1.charAt(i);
                    if (i<str1.length())
                    i++;
                }
                if(map.containsKey(str))
                    str=map.get(str);
                System.out.print(str);
                System.out.print(str1.charAt(i));
                str="";
            }
            str1=kb.nextLine();
            System.out.println();
        }
        kb.close();
    }
}