2693 - 天才小熊猫
时间限制 : 1 秒
内存限制 : 32 MB
作为学IT的精英人才,平时一定要注意保持体形。否则很有可能发生形变,比如成为这样:
<span style="font-size:10.5pt;font-family:'Times New Roman';">虽然熊猫看上去很可爱,不过胖成球就不太好了<span>……</span></span><span style="font-size:10.5pt;font-family:'Times New Roman';"></span>
<span style="font-size:10.5pt;font-family:'Times New Roman';">对了,输入球的半径,你还会计算球的体积吗?</span><span style="font-size:10.5pt;font-family:'Times New Roman';"></span>
<span style="font-size:10.5pt;font-family:'Times New Roman';">我们在这里设定<span>π</span><span>为</span><span>3.1415927</span><span>。</span></span><span style="font-size:10.5pt;font-family:'Times New Roman';"></span>
题目输入
第一行T,表示有T组数据。
接下来T行,每行由一个数k组成(0.00<k<10000.00),表示球的半径
题目输出
每组输出一个数字,表示球的体积。结果保留三位小数。
输入/输出样例
输入格式
2 1 1.5
输出格式
4.189 14.137
C语言解答
#include<stdio.h> int main() { double a,b,v; double t=3.1415927; int i; scanf("%lf",&a); for(i=0;i<a;i++) { scanf("%lf",&b); v=t*b*b*b*4.0/3.0; printf("%.3f\n",v); } }
C++解答
#define PI 3.1415927 #include <iostream> #include <cmath> #include <iomanip> #include <fstream> using namespace std; int main() { //ifstream cin; //ofstream cout; int testcase; //cin.open("b.in"); //cout.open("b.out"); double a; cin>>testcase; while(testcase--) { cin>>a; cout<<setiosflags(ios::fixed)<<setprecision(3)<<(4/3.0)*PI*pow(a,3.0)<<endl; } return 0; }
Java解答
import java.util.Scanner; class Main { public static final double PI=3.1415927; public static void main(String[] args) { Scanner reader=new Scanner(System.in); int T=reader.nextInt(); for(int i=0;i<T;i++){ double a=reader.nextDouble(); System.out.printf("%.3f",PI*(4.0/3.0)*a*a*a); if(i<T-1){ System.out.println(); } } } }