fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main(String args[])
  7. {
  8. Scanner in = new Scanner(System.in);
  9. PrintWriter out = new PrintWriter(System.out);
  10.  
  11. short Lwidth = in.nextShort(), Lheight = in.nextShort();
  12. Map alphabet = new HashMap();
  13.  
  14. if (in.hasNextLine())
  15. {
  16. in.nextLine();
  17. }
  18.  
  19. String Text = in.nextLine();
  20.  
  21. for (short h = 0; h < Lheight; ++h)
  22. {
  23. String alphabet_line = in.nextLine();
  24. short i = 0;
  25.  
  26. for(char sym = 'a', Sym = 'A'; sym <= 'z'; ++sym, ++Sym, ++i)
  27. {
  28. String letter = alphabet_line.substring(i*Lwidth, (i+1)*Lwidth);
  29. alphabet.put(sym, letter);
  30. alphabet.put(Sym, letter);
  31. }
  32. alphabet.put('?', alphabet_line.substring(i*Lwidth, (i+1)*Lwidth));
  33.  
  34. for(i = 0; i < Text.length(); ++i)
  35. {
  36. if //it is a letter
  37. (
  38. (('a' <= Text.charAt(i)) && (Text.charAt(i) <= 'z')) ||
  39. (('A' <= Text.charAt(i)) && (Text.charAt(i) <= 'Z'))
  40. )
  41. out.print(alphabet.get(Text.charAt(i)));
  42. else //it is definitely something weird
  43. out.print(alphabet.get('?'));
  44. }
  45. out.print('\n');
  46. }
  47.  
  48. out.flush();
  49. }
  50. }
Success #stdin #stdout 0.13s 29488KB
stdin
1
1
Encoding using ASCII? Hah!
?ZYXWVUTSRQPONMLKJIHGFEDCBA
stdout
WNYMXSNUAGISNUA?IYSSAAT?TA