|
|
вернуться в форумmy program for 1002 why the answer is wrong?? why the answer is wrong?? who can give me a reply? thank you very much! import java.io.BufferedInputStream; import java.util.Scanner; public class Z1002 { public static void main(String args[]) { Z1002 g=new Z1002(); g.dowork();
} int kb=0; String s=""; int c=0; String sz[]; String sjg[]; int changdu=0; int xx=0;
Scanner sca = new Scanner(new BufferedInputStream(System.in)); void get() {
s=sca.next();
xx=Integer.parseInt(""+s.charAt(0)+s.charAt(1));
if(xx!=-1) { sjg=new String[50000];
for(int i=0;i<50000;i++) { sjg[i]=""; }
c=sca.nextInt();
sz=new String[c];
for(int i=0;i<c;i++) {
sz[i]=sca.next(); }
} } void work(int x) {
String bk[]=new String[50000]; int bb=0; String mm="";
mm=duiying(s.charAt(x));
for(int i=0;i<c;i++) { for(int j=0;j<mm.length();j++) {
if(mm.charAt(j)==sz[i].charAt(0)) { bk[bb]=sz[i];
bb=bb+1; } } } for(int i=0;i<bb;i++) {
if(changdu+bk[i].length()<=s.length())
{
if(fanyi(bk[i]).equals(s.substring(x,x+bk[i].length()))) {
sjg[kb]=sjg[kb]+bk[i]+" "; changdu=changdu+bk[i].length(); if(changdu==s.length()) {
kb=kb+1; } else { if(changdu<s.length()) {
work(x+bk[i].length()); }
}
}
} }
} void paisu() { for(int i=0;i<kb;i++)//排序; { for(int j=kb-1;j>=0;j--) { if(sjg[j].length()<sjg[j-1].length()) { String t=sjg[j]; sjg[j]=sjg[j-1]; sjg[j-1]=t;
} }
}
} void out() { if(changdu!=s.length()) {
System.out.println("No solution."); changdu=0; kb=0; }else { System.out.println(sjg[0]); changdu=0; kb=0; } for(int i=0;i<50000;i++) { sjg[i]=""; } } String duiying(char x) { String fanhui=""; if(x=='0') { fanhui=fanhui+"oqz"; } if(x=='1') { fanhui=fanhui+"ij"; } if(x=='2') { fanhui=fanhui+"abc"; } if(x=='3') { fanhui=fanhui+"def"; } if(x=='4') { fanhui=fanhui+"gh"; } if(x=='5') { fanhui=fanhui+"kl"; } if(x=='6') { fanhui=fanhui+"mn"; } if(x=='7') { fanhui=fanhui+"prs"; } if(x=='8') { fanhui=fanhui+"tuv"; } if(x=='9') { fanhui=fanhui+"wxy"; } return fanhui; } String fanyi(String kk) {
int l=kk.length(); String fanhui=""; for(int i=0;i<l;i++) { if(kk.charAt(i)=='a') { fanhui=fanhui+2; } if(kk.charAt(i)=='b') { fanhui=fanhui+2; } if(kk.charAt(i)=='c') { fanhui=fanhui+2; } if(kk.charAt(i)=='d') { fanhui=fanhui+3; } if(kk.charAt(i)=='e') { fanhui=fanhui+3; } if(kk.charAt(i)=='f') { fanhui=fanhui+3; } if(kk.charAt(i)=='g') { fanhui=fanhui+4; } if(kk.charAt(i)=='h') { fanhui=fanhui+4; } if(kk.charAt(i)=='i') { fanhui=fanhui+1; } if(kk.charAt(i)=='j') { fanhui=fanhui+1; } if(kk.charAt(i)=='k') { fanhui=fanhui+5; } if(kk.charAt(i)=='l') { fanhui=fanhui+5; } if(kk.charAt(i)=='m') { fanhui=fanhui+6; } if(kk.charAt(i)=='n') { fanhui=fanhui+6; } if(kk.charAt(i)=='o') { fanhui=fanhui+0; } if(kk.charAt(i)=='p') { fanhui=fanhui+7; } if(kk.charAt(i)=='q') { fanhui=fanhui+0; } if(kk.charAt(i)=='r') { fanhui=fanhui+7; } if(kk.charAt(i)=='s') { fanhui=fanhui+7; } if(kk.charAt(i)=='t') { fanhui=fanhui+8; } if(kk.charAt(i)=='u') { fanhui=fanhui+8; } if(kk.charAt(i)=='v') { fanhui=fanhui+8; } if(kk.charAt(i)=='w') { fanhui=fanhui+9; } if(kk.charAt(i)=='x') { fanhui=fanhui+9; } if(kk.charAt(i)=='y') { fanhui=fanhui+9; } if(kk.charAt(i)=='z') { fanhui=fanhui+0; }
} return fanhui; } void dowork() {
get();
while(xx!=-1) {
work(0); out(); }
} } |
|
|