Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Can Anyone help Me???I try to solve this problem, and i tried to find some bugs in the code, i think that i get WA for some detail that i miss in the output, can anyone help me please. import java.text.DecimalFormat; import java.math.*; import java.util.*; import java.io.*; class Main { public Main () { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuffer out = new StringBuffer(); try { //BufferedReader in = new BufferedReader(new FileReader("in.txt")); DecimalFormat salida = new DecimalFormat("0.000"); String pnts=""; Point pt1 = null; Point pt2 = null; Point pt3 = null; while((pnts=in.readLine())!=null) { StringTokenizer str = new StringTokenizer(pnts); pt1=new Point(str); pt2=new Point(str); pt3=new Point(str); double yDelta_a= pt2.y - pt1.y; double xDelta_a= pt2.x - pt1.x; double yDelta_b= pt3.y - pt2.y; double xDelta_b= pt3.x - pt2.x; double x=0.0; double y=0.0; double aSlope=yDelta_a/xDelta_a; if(xDelta_a==0.0||yDelta_a==0.0)aSlope=1; double bSlope=yDelta_b/xDelta_b; if(xDelta_b==0.0||yDelta_b==0.0)bSlope=1; x= (aSlope*bSlope*(pt1.y - pt3.y) + bSlope*(pt1.x + pt2 .x)- aSlope*(pt2.x+pt3.x) )/(2* (bSlope-aSlope) ); y = -1*(x - (pt1.x+pt2.x)/2)/aSlope + (pt1.y+pt2.y)/2; double r = Math.sqrt((Math.pow(pt1.y-y,2))+(Math.pow(pt1.x-x,2))); String sx=salida.format(x*-1); sx=qs(sx,true); if(x==0) sx="x^2"; else { sx="(x "+sx+")^2"; } String sy=salida.format(y*-1); sy=qs(sy,true); if(y==0) sy="y^2"; else { sy="(y "+sy+")^2"; } sy="+ "+sy; String sr=salida.format(r); sr=qs(sr,false); out.append( sx+" "+sy+" = "+sr+"^2\n"); String sd = salida.format(2*x*-1); sd = qs(sd,true); if(2*x*-1==0) sd=""; else { sd=sd+"x "; } String se = salida.format(2*y*-1); se = qs(se,true); if(2*y*-1==0) se=""; else { se=se+"y "; } double f =((Math.pow(2*x,2)+Math.pow(2*y,2)-(4*(r*r)))/-4)*-1; String sf = salida.format(f); sf = qs(sf,true); if(f==0) sf=""; out.append("x^2 + y^2 "+sd+se+sf+" = 0\n\n"); } System.out.print(out.substring(0,out.length()-1)); } catch(Exception e){}; } public String qs(String s, boolean sm) { if(s.startsWith("-")) s = "- "+s.substring(1,s.length()); else if(sm) { s = "+ "+s; } return s; } public double m(Point p1,Point p2) { return ((p2.y-p1.y)/(p2.x-p1.x)); } public static void main(String ar[]) { new Main(); } } class Point { double x=0.0; double y=0.0; public Point(StringTokenizer str) { this.x=new Double(str.nextToken()); this.y=new Double(str.nextToken()); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator