Yu09217777 @ 2022-09-03 21:06:48
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k,cnt1 = 0,cnt2 = 0;
double sum1 = 0,sum2 = 0,avg1,avg2;
cin >> n;
cin >> k;
for (int i = 1;i <= n;i++){
if (i % k == 0){
sum1 += i;
cnt1++;
}else{
sum2 += i;
cnt2++;
}
}
avg1 = sum1 / cnt1;
avg2 = sum2 / cnt2;
cout << fixed << setprecision(1) << avg1;
cout << fixed << setprecision(1) << avg2;
return 0;
}
by xs_siqi @ 2022-09-03 21:13:16
@Yu09217777 一眼没写空格。
by Yu09217777 @ 2022-09-03 21:19:26
@xs_siqi ???
by _Healer @ 2022-09-03 21:19:28
楼上正解。
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k,cnt1 = 0,cnt2 = 0;
double sum1 = 0,sum2 = 0,avg1,avg2;
cin >> n;
cin >> k;
for (int i = 1;i <= n;i++){
if (i % k == 0) sum1 += i,cnt1++;
else sum2 += i,cnt2++;
}
avg1 = sum1/ cnt1;
avg2 = sum2/ cnt2;
cout << fixed << setprecision(1) << avg1;
cout<<' ';//这里空格要输的
cout << fixed << setprecision(1) << avg2;
return 0;
}
by _Healer @ 2022-09-03 21:19:50
@Yu09217777
by Over_fame @ 2022-09-03 21:29:40
怎么都不测试样例嘛
by Yu09217777 @ 2022-09-03 21:37:18
@_Healer 非常感谢