□Problem
省略.
□Solution
省略.
□Code
- package p1051;
- import java.util.*;
- import java.util.Map.Entry;
- import java.lang.*;
- import java.math.*;
- import java.io.*;
- import static java.lang.Math.*;
- import static java.util.Arrays.*;
- // AC
- public class Main{
- Scanner sc=new Scanner(System.in);
- final int INF=Integer.MAX_VALUE;
- final double EPS=1e-9;
- void run(){
- HashMap<Character, String> map1=new HashMap<Character, String>();
- map1.put('A', ".-");
- map1.put('B', "-...");
- map1.put('C', "-.-.");
- map1.put('D', "-..");
- map1.put('E', ".");
- map1.put('F', "..-.");
- map1.put('G', "--.");
- map1.put('H', "....");
- map1.put('I', "..");
- map1.put('J', ".---");
- map1.put('K', "-.-");
- map1.put('L', ".-..");
- map1.put('M', "--");
- map1.put('N', "-.");
- map1.put('O', "---");
- map1.put('P', ".--.");
- map1.put('Q', "--.-");
- map1.put('R', ".-.");
- map1.put('S', "...");
- map1.put('T', "-");
- map1.put('U', "..-");
- map1.put('V', "...-");
- map1.put('W', ".--");
- map1.put('X', "-..-");
- map1.put('Y', "-.--");
- map1.put('Z', "--..");
- map1.put('_', "..--");
- map1.put(',', ".-.-");
- map1.put('.', "---.");
- map1.put('?', "----");
- HashMap<String, Character> map2=new HashMap<String, Character>();
- for(Entry<Character, String> entry : map1.entrySet())
- map2.put(entry.getValue(), entry.getKey());
- int n=sc.nextInt();
- sc.nextLine();
- for(int t=1; t<=n; t++){
- String s=sc.nextLine();
- int len=s.length();
- String e="";
- int[] a=new int[len];
- for(int i=0; i<len; i++){
- e+=map1.get(s.charAt(i));
- a[i]=map1.get(s.charAt(i)).length();
- }
- String ans="";
- int k=0;
- for(int j=0; j<len; j++){
- String key="";
- for(int i=0; i<a[len-1-j]; i++)
- key+=e.charAt(k++);
- ans+=map2.get(key);
- }
- println(t+": "+ans);
- }
- }
- void print(String s){
- System.out.print(s);
- }
- void println(String s){
- System.out.println(s);
- }
- public static void main(String[] args){
- // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
- new Main().run();
- }
- }
0 件のコメント:
コメントを投稿