BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #48392同步于 2016/3/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

求助:在oj上提交总是runtime error,在eclipse则没有错误

gannanxin
2016/3/10镜像同步9 回复
import java.lang.*; import java.util.*; import java.io.*; public class Main { public static void main(String[] args)throws IOException { Scanner cin=new Scanner(System.in); while(cin.hasNext()) { int n=cin.nextInt(); if(1<=n&&n<=1000) { BufferedReader bs=new BufferedReader(new InputStreamReader(System.in)); String com[]=new String[n]; TreeSet<Num>tree=new TreeSet<Num>(); for(int i=0;i<n;i++) { com[i]=bs.readLine(); } for(int i=0;i<n;i++) { if(com[i].equals("Pop")) { if(tree.size()==0) { System.out.println("empty"); } else { System.out.println(tree.pollLast().toString()); System.out.println("SIZE = "+tree.size()); } } else if(com[i].startsWith("Insert")) { int a,b,index; index=com[i].indexOf("+"); a=Integer.valueOf(com[i].substring(7,index)); b=Integer.valueOf(com[i].substring(index+2)); Num num=new Num(a,b); tree.add(num); System.out.println("SIZE = "+tree.size()); } } } } } } class Num implements Comparable<Num>{ int i; int j; public Num(int i,int j){ this.i = i; this.j = j; } public String toString() { return i+"+i"+j; } public int compareTo(Num num) { if(this.i*this.i+this.j*this.j > num.i*num.i+num.j*num.j) return 1; else if(this.i*this.i+this.j*this.j == num.i*num.i+num.j*num.j){ if(this.j < num.j) return 1; else return 0; } else return -1; } }
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
gannanxin机器人#1 · 2016/3/10
题目描述: 一个复数(x+iy)集合,两种操作作用在该集合上: 1、Pop 表示读出集合中复数模值最大的那个复数,如集合为空 输出 empty ,不为空就输出最大的那个复数并且从集合中删除那个复数,再输出集合的大小SIZE; 2 Insert a+ib 指令(a,b表示实部和虚部),将a+ib加入到集合中 ,输出集合的大小SIZE; 最开始要读入一个int n,表示接下来的n行每一行都是一条命令。 输入: 输入有多组数据。 每组输入一个n(1<=n<=1000),然后再输入n条指令。 输出: 根据指令输出结果。 样例输入: 3 Pop Insert 1+i2 Pop 样例输出: empty SIZE = 1 1+i2 SIZE = 0
icyfox机器人#2 · 2016/3/10
在本机上没错误只是因为测试数据恰好没错误吧。 看看会不会有一些corner case导致RE
gannanxin机器人#3 · 2016/3/10
【 在 icyfox 的大作中提到: 】 : 在本机上没错误只是因为测试数据恰好没错误吧。 : 看看会不会有一些corner case导致RE Runtime Error : 运行时错误,非法的内存访问,数组越界,指针漂移,调用禁用的系统函数。 那应该是Wrong Answer呀?您能看出具体什么错吗?
icyfox机器人#4 · 2016/3/10
你能保证你的程序不会出现 null pointer 或者 array index out of range 吗? 在正常输入情况下 【 在 gannanxin 的大作中提到: 】 : Runtime Error : 运行时错误,非法的内存访问,数组越界,指针漂移,调用禁用的系统函数。 : 那应该是Wrong Answer呀?您能看出具体什么错吗?
gannanxin机器人#5 · 2016/3/10
【 在 icyfox 的大作中提到: 】 : 你能保证你的程序不会出现 null pointer 或者 array index out of range 吗? : 在正常输入情况下 数据都在eclipse上输过了,没有你说的这些错误,就是在oj上就发生runtime error错
icyfox机器人#6 · 2016/3/10
嗯? 你有OJ的测试数据? 【 在 gannanxin (lurcker) 的大作中提到: 】 : 数据都在eclipse上输过了,没有你说的这些错误,就是在oj上就发生runtime error错
youmi机器人#7 · 2016/3/10
是你的测试数据不够全
gannanxin机器人#8 · 2016/3/10
【 在 youmi 的大作中提到: 】 : 是你的测试数据不够全 30 Pop Insert 2+i1 Insert 4+i3 Insert 3+i3 Insert 1+i2 Insert 1+i2 Insert 1+i1 Insert 6+i8 Pop Pop Insert 3+i3 Pop Pop Pop Pop Pop Pop Pop Pop Pop Pop Pop Insert 2+i1 Insert 4+i3 Insert 3+i3 Pop Pop Pop Pop Insert 2+i1 empty SIZE = 1 SIZE = 2 SIZE = 3 SIZE = 3 SIZE = 3 SIZE = 4 SIZE = 5 6+i8 SIZE = 4 4+i3 SIZE = 3 SIZE = 3 3+i3 SIZE = 2 2+i1 SIZE = 1 1+i1 SIZE = 0 empty empty empty empty empty empty empty empty SIZE = 1 SIZE = 2 SIZE = 3 4+i3 SIZE = 2 3+i3 SIZE = 1 2+i1 SIZE = 0 empty SIZE = 1
gannanxin机器人#9 · 2016/3/10
【 在 youmi 的大作中提到: 】 : 是你的测试数据不够全 这是本地测试用例= =,用eclipse通过了