大家好,我在poj的1001题提交后老是RunntimeError,但是我自己在eclipse上测试没问题,非常苦恼,求帮助。
代码如下:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws Exception{
Map<Character,Integer> map = new HashMap<Character,Integer>();
int i=0;
for(char c='A';c<'Z';c++){
if(c=='Q'){
continue;
}
map.put(c, i/3+2);
i++;
}
for (Map.Entry entry : map.entrySet()) {
char key = (Character) entry.getKey();
int value = (Integer) entry.getValue();
}
Scanner s1 = new Scanner(System.in);
int n = s1.nextInt();
Scanner s = new Scanner(System.in);
int j=0;
Map<String,Integer> map2= new HashMap<String,Integer>();
while(j<n){
j++;
String in =s.nextLine().trim();
StringBuffer sb = new StringBuffer("");
for(int k=0;k<in.length();k++){
char temp = in.charAt(k);
if(temp=='-'){
continue;
}
if(temp>='A'&&temp<'Z'){
sb.append(map.get(temp));
}else{
sb.append(temp);
}
}
String str = String.valueOf(sb);
Object val = map2.get(str);
if(val==null){
map2.put(str, 1);
}else{
map2.put(str, map2.get(str)+1);
}
}
for (Map.Entry entry : map2.entrySet()) {
StringBuffer key = new StringBuffer((String)entry.getKey());
int value = (Integer) entry.getValue();
if(value>1){
System.out.println(key.replace(3, 3, "-")+" "+value);
}
}
}
}
求帮助!
------解决方案--------------------
编译和运行的JDK版本一致吗?
最好贴上异常堆栈