yutongt09 @ 2021-11-27 09:27:50
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k, a, b;
double x=0, z=0, c, d;
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
x=i+x;
b++;
}
else
{
z=i+z;
a++;
}
}
c=x/b;
d=z/a;
cout<<setiosflags(ios::fixed)<<setprecision(1)<<d<<" ";
cout<<setiosflags(ios::fixed)<<setprecision(1)<<c;
return 0;
}
by yutongt09 @ 2021-11-27 09:34:05
求助!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
by wjj255 @ 2021-11-27 09:42:53
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k, a=0, b=0;//注意初始化
double x=0, z=0, c, d;
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
x=i+x;
b++;
}
else
{
z=i+z;
a++;
}
}
c=x/b;
d=z/a;
cout<<setiosflags(ios::fixed)<<setprecision(1)<<c<<" ";
cout<<setiosflags(ios::fixed)<<setprecision(1)<<d;//先输出c,再输出d
return 0;
}
by yutongt09 @ 2021-11-27 09:47:37
@wjj255 我学到了,也过了,感谢!