Advertisement
MrJoer22

Untitled

Mar 27th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class Main {
  4.     public static void main(String[] args) throws IOException {
  5.         Scanner ent=new Scanner(System.in);
  6.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  7.         HashMap<Character,Byte>Systema=new HashMap<>();
  8.         byte N=Byte.parseByte(br.readLine());
  9.         for(byte i=0;i<N;i++){
  10.             StringTokenizer jg=new StringTokenizer(br.readLine());
  11.            
  12.             Systema.put(jg.nextToken().charAt(0),Byte.parseByte(jg.nextToken()));
  13.         }
  14.         short K=Short.parseShort(br.readLine());
  15.         for(short i=0;i<K;i++){
  16.             String word=br.readLine();
  17.             byte exp=(byte)(word.length()-1);
  18.             byte exp2=0;
  19.             long num=0;
  20.             while(exp>-1){
  21.                 num+=(Systema.get(word.charAt(exp2))*Math.pow(N,exp));
  22.                 exp--;
  23.                 exp2++;
  24.             }
  25.             System.out.println(num);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement