【題目敘述】https://zerojudge.tw/ShowProblem?problemid=b561
#include <iostream>
#include <iomanip>
using namespace std;
int n;
int main() {
while (cin >> n){
int a = 0, b = 0;
for (int i = 0, x; i < n; i++){
cin >> x;
a += x*x;
}
cin >> n;
for (int i = 0, x; i < n; i++){
cin >> x;
b += x*x;
}
cout << fixed << setprecision(2) << double(abs(a-b))/4*3.14159 << "\n";
}
}
Python code (credit: Amy Chou)
PI = 3.14159
while True:
try:
tmp = list(map(int, input().split()))
sum1 = 0
for i in range(tmp[0]):
sum1 += PI * tmp[i+1] * tmp[i+1] / 4
tmp = list(map(int, input().split()))
sum2 = 0
for i in range(tmp[0]):
sum2 += PI * tmp[i+1] * tmp[i+1] / 4
print(f"{round(abs(sum1 - sum2),2):.2f}")
except:
break