|  | 
|  | 
| вернуться в форум | WA with cout AC with printf This is terribly hilarious people. No precision details have been given in the question. Yet printf("%.5f",val); worked but cout<<val; didnt(WA#4). BTW the method i followed is: Find the volume of the pyramid vol(h,w)=hw*w/3 (i got it by integrating the squares at heights from 0 to h) Find the volume of the truncated cylinder using the method given inhttp://mathworld.wolfram.com/CylindricalSegment.html subtract the second from the first.C++ and Java I couldnt accept this task in C++.
 #include<iostream>
 #include<math.h>
 using namespace std;
 
 int main()
 {
 double w,h,x,y,r,t;
 cin >> w >> h >> x >> y >> r;
 x = fabs(x);
 y = fabs(y);
 if ( y > x ) x = y;
 printf("%.5lf", h * w * w / 3.0 - h * 3.14159265358979 * r * r * ( w/2 - x ) / (w/2));
 return 0;
 }
 
 take WA3, but analogical
 
 
 
 import java.io.*;
 import java.util.*;
 
 public class Problem1550 {
 
 /**
 * @param args
 */
 public static void main(String[] args)
 throws IOException
 {
 Scanner in=new Scanner(System.in);
 //Scanner in=new Scanner(new File("input.txt"));
 PrintWriter out=new PrintWriter(System.out);
 double h,w,x,y,r;
 h=in.nextDouble();
 w=in.nextDouble();
 x=in.nextDouble();
 y=in.nextDouble();
 r=in.nextDouble();
 x=Math.abs(x);
 y=Math.abs(y);
 if(y>x)x=y;
 w=h*w*w/3-(Math.PI*r*r*(h*(w/2-x)/(w/2)));
 out.println(Double.toString(w));
 out.flush();
 }
 }
 
 in Java - accepted. I hate this problem!
Re: C++ and Java Послано vav  9 апр 2008 21:08there is mistake in c++ code
 Edited by author 09.04.2008 21:14
Re: C++ and Java Послано SHY  9 апр 2008 21:12Here is a very fool mistake in C++ code but Java code is alright. I made this mistake in my Pascal code but then i read the problem attentively and found it.Re: C++ and Java import java.io.*;import java.util.*;
 
 public class Problem1550 {
 
 /**
 * @param args
 */
 public static void main(String[] args)
 throws IOException
 {
 Scanner in=new Scanner(System.in);
 //Scanner in=new Scanner(new File("input.txt"));
 PrintWriter out=new PrintWriter(System.out);
 double h,w,x,y,r;
 h=in.nextDouble();
 w=in.nextDouble();
 x=in.nextDouble();
 y=in.nextDouble();
 r=in.nextDouble();
 x=Math.abs(x);
 y=Math.abs(y);
 if(y>x)x=y;
 w=h*w*w/3-(Math.PI*r*r*(h*(w/2-x)/(w/2)));
 out.println(Double.toString(w));
 out.flush();
 }
 }
 Your solution is not right. I use out.printf(Locale.US,"%.4f",(piramideVolume-cylindricalSegmentVolume));  to get AC!Re: C++ and Java In Santa's code above, changecin>>w>>h
 to
 cin>>h>>w
 will be OK.
 
 That's really a small but serious bug.
 | 
 | 
|