import java.io.*; /* * * @author David Alvarez Lopez * @email sly.dekar@gmail.com * @date 21-Oct-05 * */ public class brokenKeyboard { private static PrintWriter stdOut = new PrintWriter(System.out,true); private static PrintWriter stdErr = new PrintWriter(System.out,true); public static void main(String[] args) throws IOException { try { BufferedReader fileIn = new BufferedReader(new FileReader("C:/input.txt")); String sBroken = fileIn.readLine(); sBroken = inverseCaps(sBroken); int keyboard = 1; String buffer = new String("+----------+----------------+-----------------------------+\n| Keyboard | # of printable | Additionally, the following |\n| | lines | letter keys can be broken |\n+----------+----------------+-----------------------------+"); while (!sBroken.equals("finishFINISH")) { String s = new String(); String concat = new String(); String otherBK = new String(); int nPL = 0; while (!s.equals("END")) { s = fileIn.readLine(); if (!isPrintable(s,sBroken)) { //stdOut.println(s); concat += s; nPL++; } } if (concat.length() > 0) { otherBK = otherBrokenKeys(concat, sBroken); //stdOut.println(otherBK); } buffer += "\n| "+keyboard; for (int i = 0; i<5-(keyboard+"").length(); i++) { buffer += " "; } buffer += "| "+nPL; for (int i = 0; i<8-(nPL+"").length(); i++) { buffer += " "; } buffer += "| "+otherBK; for (int i = 0; i<28-otherBK.length(); i++) { buffer += " "; } buffer += "|\n+----------+----------------+-----------------------------+"; sBroken = fileIn.readLine(); sBroken = inverseCaps(sBroken); keyboard++; } stdOut.println(buffer); } catch (IOException ioe) { stdOut.println("ERROR: File Not Found" + ioe.toString()); } } private static boolean isPrintable(String s, String sBroken) { for (int i = 0; i 64) && (s.charAt(i) < 90)) || ((s.charAt(i) > 96) && (s.charAt(i) < 121))) { int n = s.charAt(i)-97; if (n<0) { n += 32; } otherKeys[n] = 0; } } String ret = new String(); for (int i = 0; i<26; i++) { if (otherKeys[i] != 0 && !brokenKeyFound((char) otherKeys[i],sBroken)) { ret += (char) otherKeys[i]; } } //stdOut.println(ret); return ret; } private static String inverseCaps(String s) { String nueva = new String(); for (int i = 0; i 96) { nueva += (char) (s.charAt(i) - 32); } } } return s + nueva; } }