/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package epithets; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Scanner; /** * * @author Michael Shihrer, Hakan Celik */ public class Epithets { private static int[] values; /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { Scanner in = new Scanner(new File("epithets.in")); PrintWriter out = new PrintWriter(new FileWriter("epithets.out")); values = new int[27]; for(int i = 0; i < 27; i++) { values[i] = in.nextInt(); } in.nextLine(); while(in.hasNextLine()) { String square = in.nextLine(); String word = in.nextLine(); out.print(computeScore(word, square)); if(in.hasNextLine()) out.println(); } out.close(); } private static long computeScore(String word, String square) { int score = 0; for(int i = 0; i < word.length(); i++) { int letterScore = 0; //get base score letterScore = values[getLetterPlace(word.charAt(i))]; //Check for square bonus if(square.charAt(i) == '2') { letterScore *= 2; } else if(square.charAt(i) == '3') { letterScore *= 3; } score += letterScore; } //Check for word bonuses long wordBonus = 1; if(square.contains("d") || square.contains("t")) { for(int i = 0; i < square.length(); i++) { if(square.charAt(i) == 'd') wordBonus *= 2; else if(square.charAt(i) == 't') wordBonus *= 3; } } return score * wordBonus; } private static int getLetterPlace(char theChar) { char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_'}; boolean found = false; int index = 0; while(!found) { if(alphabet[index] == Character.toLowerCase(theChar)) found = true; else index++; } return index; } }