python求圆柱表面积_ZZULIOJ.1011: 圆柱体表面积 —— 1021:三个整数的最大值(C语言 Vs Python)...
目錄
1011: 圓柱體表面積
1012: 求絕對(duì)值
1013: 求兩點(diǎn)間距離
1014: 求三角形的面積
1015: 計(jì)算時(shí)間間隔
1016: 銀行利率
1017: 判斷正整數(shù)位數(shù)
1018: 奇數(shù)偶數(shù)
1019: 公園門票
1020: 兩整數(shù)排序
1021: 三個(gè)整數(shù)的最大值
1011: 圓柱體表面積
題目描述
輸入圓柱體的底面半徑r和高h(yuǎn),計(jì)算圓柱體的表面積并輸出到屏幕上。要求定義圓周率為如下宏常量
#define PI 3.14159
輸入 輸入兩個(gè)實(shí)數(shù),為圓柱體的底面半徑r和高h(yuǎn)。
輸出 輸出一個(gè)實(shí)數(shù),即圓柱體的表面積,保留2位小數(shù)。
樣例輸入 Copy
42.1 71.6
樣例輸出 Copy
30076.14
#include
#define pi 3.14159
int main(void)
{
double r, h, s;
scanf("%lf%lf", &r, &h);
s = pi * r * r * 2 + 2 * pi * r * h;
printf("%.2f\n", s);
return 0;
}
Vs
pi = 3.14159
r,h =map(float,input().split())
s = pi * r *r * 2 + 2 * pi * r * h
print("%.2f" %(s))
1012: 求絕對(duì)值
題目描述
求實(shí)數(shù)的絕對(duì)值。
輸入 輸入一個(gè)實(shí)數(shù)。
輸出 輸出它的絕對(duì)值,結(jié)果保留兩位小數(shù)
樣例輸入 Copy
-234.00
樣例輸出 Copy
234.00
#include
int main(void)
{
double a, b;
scanf("%lf", &a);
b = fabs (a);
printf("%.2f\n", b);
return 0;
}
Vs
import math
x = float(input())
y = math.fabs (x)
print("%.2f" %(y))
1013: 求兩點(diǎn)間距離
題目描述
給定A(x1, y1), B(x2, y2)兩點(diǎn)坐標(biāo),計(jì)算它們間的距離。
輸入 輸入包含四個(gè)實(shí)數(shù)x1, y1, x2, y2,分別用空格隔開,含義如描述。其中0≤x1,x2,y1,y2≤100。
輸出 輸出占一行,包含一個(gè)實(shí)數(shù)d,表示A, B兩點(diǎn)間的距離。結(jié)果保留兩位小數(shù)。
樣例輸入 Copy
1 1 2 2
樣例輸出 Copy
1.41
#include
#include
int main(void)
{
double x1, y1, x2, y2, dist;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
dist = sqrt ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
printf("%.2f\n", dist);
return 0;
}
Vs
import math
x1,y1,x2,y2 = map(float,input().split())
d = math.sqrt((x2 -x1) ** 2 + (y2 - y1) ** 2)
print("%.2f" %(d))
1014: 求三角形的面積
題目描述
給出三角形的三條邊,求三角形的面積。
輸入 輸入三角形的三條邊長(zhǎng)(實(shí)數(shù)),數(shù)據(jù)之間用空格隔開。
輸出 輸出三角形的面積,結(jié)果保留2位小數(shù)。
樣例輸入 Copy
2.5 4 5
樣例輸出 Copy
4.95
提示
用海倫公式或其他方法均可。
#include
#include
int main(void)
{
double a, b, c, p, s;
scanf("%lf%lf%lf", &a, &b, &c);
p = (a + b + c)/2;
s = sqrt(p * (p-a) * (p-b) * (p-c));
printf("%.2f\n",s);
return 0;
}
Vs
import math
a,b,c = map(float,input().split())
p = (a + b + c) / 2
s = math.sqrt(p * (p - a) * (p - b) * (p -c))
print("%.2f" %(s))
1015: 計(jì)算時(shí)間間隔
題目描述
讀入兩個(gè)用“時(shí):分:秒”表示的時(shí)間點(diǎn),計(jì)算以秒為單位的時(shí)間間隔。
輸入 輸入有兩行,每行是一個(gè)用“時(shí):分:秒”表示的時(shí)間點(diǎn)。測(cè)試數(shù)據(jù)保證第二個(gè)時(shí)間點(diǎn)晚于第一個(gè)時(shí)間點(diǎn)。
輸出 輸出一個(gè)整數(shù),表示時(shí)間間隔的秒數(shù)。
樣例輸入 Copy
08:00:00
09:00:00
樣例輸出 Copy
3600
#include
#include
int main()
{
int x1,x2,y1,y2,z1,z2,sum1,sum2;
scanf("%d:%d:%d",&x1,&y1,&z1);
scanf("%d:%d:%d",&x2,&y2,&z2);
sum1=3600*x1+60*y1+z1;
sum2=3600*x2+60*y2+z2;
printf("%d",sum2-sum1);
}
Vs
import math
# x表示時(shí),y表示分,z表示秒
x1,y1,z1 = map(int,input().split(":"))
x2,y2,z2 = map(int,input().split(":"))
sum1 = 3600 * x1 + 60 * y1 + z1
sum2 = 3600 * x2 + 60 * y2 + z2
print(int(sum2-sum1))
1016: 銀行利率
題目描述
設(shè)銀行1年期定期存款年利率為2.25%,存款本金為deposit元,試編程計(jì)算并輸出n年后的本利之和。
輸入 輸入一個(gè)正整數(shù)和一個(gè)實(shí)數(shù),分別代表存款年數(shù)和存款本金。
輸出 輸出一個(gè)雙精度實(shí)數(shù),小數(shù)點(diǎn)后保留6位有效數(shù)字。
樣例輸入 Copy
2 100
樣例輸出 Copy
104.550625
#include
#include
#define pi 0.0225
int main()
{
int n;
double deposit,sum;
scanf("%d%lf",&n,&deposit);
sum=deposit*pow(1+pi,n);
printf("%.6lf",sum);
}
Vs
import math
pi = 0.0225 #pi 為年利率
n,deposit = map(float,input().split())
sum = deposit * math.pow(1 + pi , n)
print("%.6f" %sum)
1017: 判斷正整數(shù)位數(shù)
題目描述
給定一個(gè)不多于5位的正整數(shù),判斷它是幾位數(shù),并輸出。
輸入 一個(gè)不多于5位的正整數(shù)。
輸出 輸出正整數(shù)的位數(shù),單獨(dú)占一行。
樣例輸入 Copy
111
樣例輸出 Copy
3
#include
int main(void)
{
int a, len;
scanf("%d", &a);
len = (int)log10(a) + 1;
printf("%d\n", len);
return 0;
}
Vs
import math
a = int(input())
x = (int)(math.log10(a)) + 1
print(x)
#或者
a = int(input())
print(len(str(a)))
1018: 奇數(shù)偶數(shù)
題目描述
輸入一個(gè)整數(shù),判斷該數(shù)是奇數(shù)還是偶數(shù)。
輸入 輸入整數(shù)n。
輸出 如果該數(shù)是奇數(shù)就輸出“odd”,偶數(shù)就輸出“even”(輸出不含雙引號(hào))。
樣例輸入 Copy
8
樣例輸出 Copy
even
#include
int main(void)
{
int n;
scanf("%d",&n);
if(n%2==0)
printf("even");
else
printf("odd");
}
Vs
n = int(input())
if n % 2 == 0:
print("even")
else:
print("odd")
1019: 公園門票
題目描述
某公園門票的票價(jià)是每人50元,一次購(gòu)票滿30張,每張可以少收2元。試編寫自動(dòng)計(jì)費(fèi)系統(tǒng)程序。
輸入 輸入一個(gè)正整數(shù),表示購(gòu)票的數(shù)量。
輸出 輸出一個(gè)整數(shù),表示用戶實(shí)際需要支付的金額。
樣例輸入 Copy
30
樣例輸出 Copy
1440
#include
int main(void)
{
int x, y;
scanf("%d", &x);
if(x<30)
y = 50*x;
else
y = 48*x;
printf("%d\n",y);
}
Vs
x = int(input())
if x < 30:
print(50 * x )
else:
print(48 * x )
1020: 兩整數(shù)排序
題目描述
從鍵盤輸入兩個(gè)整數(shù)x,y,按從小到大的順序輸出它們的值。
輸入 輸入兩個(gè)整數(shù)x,y。
輸出 按從小到大的順序輸出它們的值。數(shù)據(jù)之間以空格間隔。
樣例輸入 Copy
20 16
樣例輸出 Copy
16 20
#include
int main(void)
{
int a, b, t;
scanf("%d%d",&a, &b);
if(a>b)
{
t = a;
a = b;
b = t;
}
printf("%d %d\n", a, b);
return 0;
}
Vs
a,b = map(int,input().split())
if a > b :
t = a
a = b
b = t
print("%d %d" %(a,b))
1021: 三個(gè)整數(shù)的最大值
題目描述
從鍵盤輸入三個(gè)整數(shù)x,y和z,求出其中最大的數(shù)。
輸入 輸入三個(gè)整數(shù),用空格隔開。
輸出 輸出最大整數(shù)。
樣例輸入 Copy
20 16 18
樣例輸出 Copy
20
#include
int main(void)
{
int x, y, z, max;
scanf("%d%d%d", &x, &y, &z);
max = (x>y) ? x : y;
max = (z>max) ? z : max;
printf("%d\n",max);
return 0;
}
Vs
x,y,z = map(int,input().split())
if x > y:
max = x
else:
max = y
if z > max:
max = z
print(max)
總結(jié)
以上是生活随笔為你收集整理的python求圆柱表面积_ZZULIOJ.1011: 圆柱体表面积 —— 1021:三个整数的最大值(C语言 Vs Python)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: c#实现权限设置
- 下一篇: 高速数据采集卡的数据参数表征