Created
August 27, 2013 08:18
-
-
Save alcedo/6350988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.Scanner; | |
import static java.lang.System.out; | |
/** | |
* mistake: did not use BufferedReader to read in large files, resulting in very slow run time :-( | |
* try not to declare new variables in loops too . | |
*/ | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
//Scanner in = new Scanner(System.in); | |
StringBuffer sb = new StringBuffer(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
int tests = Integer.parseInt(br.readLine()); | |
while(tests != 0) { | |
int K = Integer.parseInt(br.readLine()); | |
HashMap<Character,Integer> hm = new HashMap<Character, Integer>(); | |
long sum = 0; | |
String line; | |
for(int i=0; i<K; i++) { | |
line = br.readLine(); | |
char c = line.charAt(0); | |
hm.put(c, Integer.parseInt(line.substring(1).trim())); | |
// System.out.println(c + " " + Integer.parseInt(line.substring(1).trim())); | |
} | |
int M = Integer.parseInt(br.readLine()); | |
for(int i=0;i<M; i++) { | |
line = br.readLine(); | |
//out.println(line); | |
char[] chars = line.toCharArray(); | |
for(char c : chars) { | |
if(hm.containsKey(c)){ | |
sum+=hm.get(c); | |
} | |
} | |
} | |
System.out.format("%.2f$%n", (double) sum/100); | |
tests--; | |
} | |
}//end of void main | |
}//end of class main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment