水户洋平_ @ 2020-08-22 17:02:49
40分的代码..如何改进
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,k;
float a=0.0,b=0.0,num1=0.0,num2=0.0;
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
a+=i;
num1++;
}else{
b+=i;
num2++;
}
}
cout<<fixed<<setprecision(1)<<a/num1<<" "<<b/num2<<endl;
return 0;
}
by taoyi_01 @ 2020-08-23 12:01:07
改成double就可以了