2010年10月2日土曜日

PKU Judge Online 1051 P,MTHBGWB

■1051 P,MTHBGWB

□Problem
省略.

□Solution
省略.

□Code
  1. package p1051;  
  2.   
  3. import java.util.*;  
  4. import java.util.Map.Entry;  
  5. import java.lang.*;  
  6. import java.math.*;  
  7. import java.io.*;  
  8.   
  9. import static java.lang.Math.*;  
  10. import static java.util.Arrays.*;  
  11.   
  12. // AC  
  13. public class Main{  
  14.   
  15.     Scanner sc=new Scanner(System.in);  
  16.   
  17.     final int INF=Integer.MAX_VALUE;  
  18.     final double EPS=1e-9;  
  19.   
  20.     void run(){  
  21.         HashMap<Character, String> map1=new HashMap<Character, String>();  
  22.         map1.put('A'".-");  
  23.         map1.put('B'"-...");  
  24.         map1.put('C'"-.-.");  
  25.         map1.put('D'"-..");  
  26.         map1.put('E'".");  
  27.         map1.put('F'"..-.");  
  28.         map1.put('G'"--.");  
  29.   
  30.         map1.put('H'"....");  
  31.         map1.put('I'"..");  
  32.         map1.put('J'".---");  
  33.         map1.put('K'"-.-");  
  34.         map1.put('L'".-..");  
  35.         map1.put('M'"--");  
  36.         map1.put('N'"-.");  
  37.   
  38.         map1.put('O'"---");  
  39.         map1.put('P'".--.");  
  40.         map1.put('Q'"--.-");  
  41.         map1.put('R'".-.");  
  42.         map1.put('S'"...");  
  43.         map1.put('T'"-");  
  44.         map1.put('U'"..-");  
  45.   
  46.         map1.put('V'"...-");  
  47.         map1.put('W'".--");  
  48.         map1.put('X'"-..-");  
  49.         map1.put('Y'"-.--");  
  50.         map1.put('Z'"--..");  
  51.   
  52.         map1.put('_'"..--");  
  53.         map1.put(','".-.-");  
  54.         map1.put('.'"---.");  
  55.         map1.put('?'"----");  
  56.   
  57.         HashMap<String, Character> map2=new HashMap<String, Character>();  
  58.         for(Entry<Character, String> entry : map1.entrySet())  
  59.             map2.put(entry.getValue(), entry.getKey());  
  60.   
  61.         int n=sc.nextInt();  
  62.         sc.nextLine();  
  63.         for(int t=1; t<=n; t++){  
  64.             String s=sc.nextLine();  
  65.             int len=s.length();  
  66.             String e="";  
  67.             int[] a=new int[len];  
  68.             for(int i=0; i<len; i++){  
  69.                 e+=map1.get(s.charAt(i));  
  70.                 a[i]=map1.get(s.charAt(i)).length();  
  71.             }  
  72.             String ans="";  
  73.             int k=0;  
  74.             for(int j=0; j<len; j++){  
  75.                 String key="";  
  76.                 for(int i=0; i<a[len-1-j]; i++)  
  77.                     key+=e.charAt(k++);  
  78.                 ans+=map2.get(key);  
  79.             }  
  80.             println(t+": "+ans);  
  81.         }  
  82.     }  
  83.   
  84.     void print(String s){  
  85.         System.out.print(s);  
  86.     }  
  87.   
  88.     void println(String s){  
  89.         System.out.println(s);  
  90.     }  
  91.   
  92.     public static void main(String[] args){  
  93.         // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));  
  94.         new Main().run();  
  95.     }  
  96. }  

0 件のコメント: