問(wèn)題 1900: [藍(lán)橋杯][算法提高VIP]摩爾斯電碼
題目描述
摩爾斯電碼破譯薪者。類似于喬林教材第213頁(yè)的例6.5,要求輸入摩爾斯碼址晕,返回英文痹愚。請(qǐng)不要使用"zylib.h",只能使用標(biāo)準(zhǔn)庫(kù)函數(shù)入篮。用' * '表示' . '陈瘦,中間空格用' | '表示,只轉(zhuǎn)化字符表潮售。
摩爾斯碼定義見(jiàn):http://baike.baidu.com/view/84585.htm?fromId=253988痊项。
輸入
無(wú)
輸出
無(wú)
樣例輸入
無(wú)
樣例輸出
無(wú)
package 字符串;
import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* User: 76147
* Date: 2020-01-29
* Time: 21:47
* Description: 暴力法
*/
public class 摩爾斯電碼 {
static String[] f = {"*-", "-***", "-*-*", "-**", "*", "**-*",
"-**", "****", "**", "*---", "-*-", "*-**", "--", "-*",
"---", "*--*", "--*-", "*-*", "***", "-", "**-", "***-",
"*--", "-**-", "-*--", "--**"};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String arr[] = sc.next().split("\\|");
String res = "";
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < f.length; j++) {
if (arr[i].equals(f[j])) {
res += (char)('a'+j);
}
}
}
System.out.println(res);
}
}
}
注意 分隔符|,需要用
\\|來(lái)轉(zhuǎn)義
輸出要小寫(xiě)