problem1075 what are you talking about?

<span style="font-family: Arial, Helvetica, sans-serif;">import java.util.*;</span>
public class Main1075 {
	public static void main(String[] args) {
		HashMap<String, String> hm = new HashMap<String, String>();         //定义一个map来存储字典对
		Scanner cin = new Scanner(System.in);
		if (cin.next().equals("START")) {
			String word;
			while (!(word = cin.next()).equals("END")) {                //从START读到END,注意放入顺序,火星文—地球文
				hm.put(cin.next(), word);
			}
		}
		cin.nextLine();                                                     //这边要跳到下一行,因为此时还指在END所在行,否则会出错
		if (cin.nextLine().equals("START")) {

			String word;
			while (!(word = cin.nextLine()).equals("END")) {            
				StringBuilder sb = new StringBuilder();             //创建StringBuilder来存储每一个字符串,注意每读完一个单词后要清空
				for (int i = 0; i < word.length(); i++) {

					char zm = word.charAt(i);                   
					if (zm <= 'z' && zm >= 'a') {
						sb.append(zm);

					}
					if (!(zm <= 'z' && zm >= 'a')) {

						if (sb != null && hm.get(sb.toString()) != null)
							System.out.print(hm.get(sb.toString()));    //一旦出现非a~z的字符,说明前一个单词添加完毕,如
                                                <span style="font-family: Arial, Helvetica, sans-serif;">else    </span><span style="font-family: Arial, Helvetica, sans-serif;">System.out.print(sb);                                                      //果有对应的字典值,就打印,没有就原样输出</span>
						sb.delete(0, sb.length());
						System.out.print(zm);                               //接着输出本字符
					}

				}
				System.out.println();
			}
		}

	}
}

你可能感兴趣的:(HashMap,字典翻译)