01:A+B问题
python编程
a, b = map(int, input().split()) print(a+b)
C++编程
#include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; cout<<a+b; }
02:计算(a+b)*c的值
python编程
a, b, c = map(int, input().split()) print((a+b)*c)
C++编程
#include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<(a+b)*c; }
03:计算(a+b)/c的值
python编程
import math a, b, c = map(int, input().split()) result = (a + b)/c if result >= 0: result = math.floor(result) else: result = math.ceil(result) print(result)
C++编程
#include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<(a+b)/c<<endl; }
04:带余除法
python编程
import math a, b = map(int, input().split()) result = a/b if result >= 0: result = math.floor(result) else: result = math.ceil(result) print(result, a - (result*b), sep=' ')
C++编程
#include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; cout<<a/b<<" "<<a%b<<endl; }
05:计算分数的浮点数值
python编程
a, b = map(int, input().split()) print('%.9f' % (a/b))
C++编程
#include<iostream> #include<iomanip> using namespace std; int main() { int a,b; cin>>a>>b; double c=(a*1.0)/b; cout<<fixed<<setprecision(9)<<c<<endl; }
06:甲流疫情死亡率
python编程
a, b = map(int, input().split()) print('%.3f%%' % (b*100/a))
C++编程
#include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; printf("%.3f%%\n",(b*100*1.0)/a); }
07:计算多项式的值
python编程
x, a, b, c, d = map(float, input().split()) result = a*x*x*x + b*x*x + c*x + d print('%.7f' % result)
C++编程
#include<iostream> using namespace std; int main() { double x,a,b,c,d; cin>>x>>a>>b>>c>>d; double f=a*x*x*x+b*x*x+c*x+d; printf("%.7f",f); }
08:温度表达转换
python编程
f = float(input()) C = 5*(f-32)/9 print('%.5f' % C)
C++编程
#include<iostream> using namespace std; int main() { double f; cin>>f; double C=5*(f-32)/9; printf("%.5f",C); }
09:与圆相关的计算
python编程
r = float(input()) pi = 3.14159 diameter = 2*r perimeter = 2*pi*r area = pi*r*r print('%.4f %.4f %.4f' % (diameter, perimeter, area))
C++编程
#include<iostream> using namespace std; int main() { double r,pi=3.14159; cin>>r; double l=2*r,c=2*pi*r,s=pi*r*r; printf("%.4f %.4f %.4f",l,c,s); }
10:计算并联电阻的阻值
python编程
r1, r2 = map(float, input().split()) R = 1/(1/r1 + 1/r2) print('%.2f' % R)
here have a wrong
C++编程
#include<iostream> using namespace std; int main() { float r1,r2; cin>>r1>>r2; float R=r1*r2/(r1+r2); printf("%.2f",R); }
11:计算浮点数相除的余数
python编程
a, b = map(float, input().split()) result = a % b print('%g' % result)
C++编程
#include<stdio.h> #include<math.h> int main() { double a,b,r; int k; scanf("%lf%lf",&a,&b); k=a/b; r=a-(b*k); printf("%g\n",r); return 0; }
12:计算球的体积
python编程
r = float(input()) pi = 3.14 volume = (4*pi*r*r*r)/3 print('%.2f' % volume)
C++编程
#include<iostream> using namespace std; int main() { double r,pi=3.14; cin>>r; double v=(4.0/3)*pi*r*r*r; printf("%.2f",v); }
13:反向输出一个三位数
python编程
n = int(input()) print(n % 10, (n % 100)//10, n//100,sep='')
C++编程
#include<iostream> using namespace std; int main() { int a; cin>>a; cout<<a%10<<(a%100)/10<<a/100; }
14:大象喝水
python编程
import math h, r = map(float, input().split()) pi = 3.14159 volume = pi*r*r*h*pow(10, -3) print(math.ceil(20/volume))
C++编程
#include<iostream> using namespace std; int main() { int h,r; double pi=3.14159; cin>>h>>r; int x=20000/(pi*r*r*h)+1; cout<<x; }
15:苹果和虫子
python编程
import math n, x, y = map(int, input().split()) residue = n - math.ceil(y/x) print(residue)
C++编程
#include<iostream> using namespace std; int main() { int n,x,y; cin>>n>>x>>y; double m=y*1.0/x; int m1=y/x; if(m-m1==0) cout<<n-m1; else cout<<n-m1-1; }
16:计算线段长度
python编程
import math xa, ya = map(float, input().split()) xb, yb = map(float, input().split()) distance = math.sqrt((xa - xb)*(xa - xb) + (ya - yb)*(ya - yb)) print('%.3f' % distance)
C++编程
#include<iostream> #include<cmath> using namespace std; int main() { double xa,ya,xb,yb; cin>>xa>>ya; cin>>xb>>yb; double l=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); printf("%.3f",l); }
17:计算三角形面积
python编程
import math x1, y1, x2, y2, x3, y3 = map(float, input().split()) distance1 = math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)) distance2 = math.sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3)) distance3 = math.sqrt((x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2)) L = (distance1 + distance2 + distance3)/2 area = math.sqrt(L*(L - distance3)*(L - distance2)*(L - distance1)) print('%.2f' % area)
C++编程
#include<iostream> #include<cmath> using namespace std; int main() { double x1,y1,x2,y2,x3,y3; cin>>x1>>y1>>x2>>y2>>x3>>y3; double L1,L2,L3,L,s; L1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); L2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); L3=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)); L=(L1+L2+L3)/2; s=sqrt(L*(L-L1)*(L-L2)*(L-L3)); printf("%.2f",s); }
18:等差数列末项计算
python编程
a1, a2, n = map(int, input().split()) result = a1 + (a2 - a1)*(n - 1) print(result)
C++编程
#include<iostream> using namespace std; int main() { int a1,a2,n; cin>>a1>>a2>>n; cout<<(n-1)*(a2-a1)+a1; }
19:A*B问题
python编程
A, B = map(int, input().split()) print(A*B)
C++编程
#include<iostream> using namespace std; int main() { unsigned int a,b,c; cin>>a>>b; c=a*b; cout<<c; }
20:计算2的幂
python编程
n = int(input()) print(pow(2, n))
C++编程
#include<iostream> using namespace std; int main() { unsigned int n,s=1; cin>>n; for(int i=0;i<n;++i) s*=2; cout<<s; }