|
|
back to boardRestricted Function !! I dont Know What the error mean and what the wrong with the code !! I appreciate if someone explain it for me =)
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Stack; public class Telenum { public static int num(char s) { int y = 0; if ((s == 'i') || (s == 'j')) { y = 1; } if ((s == 'a') || (s == 'b') || (s == 'c')) { y = 2; } if ((s == 'd') || (s == 'e') || (s == 'f')) { y = 3; } if ((s == 'g') || (s == 'h')) { y = 4; } if ((s == 'k') || (s == 'l')) { y = 5; } if ((s == 'm') || (s == 'n')) { y = 6; } if ((s == 'p') || (s == 'r') || (s == 's')) { y = 7; } if ((s == 't') || (s == 'u') || (s == 'v')) { y = 8; } if ((s == 'w') || (s == 'x') || (s == 'y')) { y = 9; } if ((s == 'o') || (s == 'q') || (s == 'z')) { y = 0; } return y; } public static void main(String[] args) throws FileNotFoundException { Scanner sc = new Scanner(new File("pp")); String phonum = "", w1, w2 = null,l="", word = ""; int wn = 0, numtr, phnum, flag; boolean f = true; char Takechar = ' '; Stack st1 = new Stack(); Stack st2 = new Stack(); while (f != false) { phonum = "" + sc.next();
if (phonum.equals("-1")) { break; } wn = sc.nextInt(); if ((phonum.length()<=100)&&(wn<=50000)){ for (int i = 0; i < wn; i++) { l=sc.next(); if (l.length()<51){ st1.add(l);}else{break;} } //transfare word to num for (int i = 0; i < st1.size(); i++) { word = (String) st1.get(i);
flag = word.length(); for (int j = 0; j < word.length(); j++) { Takechar = word.charAt(j); numtr = num(Takechar);
phnum = phonum.charAt(j) - '0';
if (numtr != phnum) { break; } flag--; if (flag == 0) { st2.add(word); w1 = phonum.substring(word.length()); phonum = "" + w1; } } } if (st2.empty()) { System.out.println("no solution."); st1.clear(); } else { for (int s = 0; s < st2.size(); s++) { System.out.print(st2.get(s) + " "); } System.out.println(); st2.clear(); st1.clear(); } } } } } |
|
|