import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
sc.nextLine();
Map<String, Integer> map = new HashMap<String, Integer>(4 * m / 3 + 1);
for (int i = 0; i < m; i++)
{
String s = sc.nextLine().trim();
String[] ss = s.split("\\s+");
map.put(ss[0].trim(), Integer.parseInt(ss[1]));
}
for (int i = 0; i < n; i++)
{
String s = sc.nextLine().trim();
StringBuilder sb = new StringBuilder();
while (!".".equals(s))
{
sb.append(s).append(" ");
s = sc.nextLine().trim();
}
int sum = 0;
for (String temp : sb.toString().split("\\s+"))
{
Integer ii = map.get(temp.trim());
if (ii != null)
sum += ii;
}
System.out.println(sum);
}
}
}
ZOJ-1902
最新推荐文章于 2019-06-05 17:53:42 发布