Cat_Jack @ 2024-08-08 14:45:47
为什么全都紫了?```c
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,a = 0,b = 0,za = 0,zb = 0;
double ansa = za/a,ansb = zb/b;
cin>>n>>k;
for (int i = 1;i<=n;i++){
if (i%k == 0){
a++;
za += i;
}
else{
b++;
zb += i;
}
}
printf("%.1lf %.1lf\n",ansa,ansb);
return 0;
}
by lovely_codecat @ 2024-08-08 14:47:13
因为除0,要在处理完后再除
by ImposterAnYu @ 2024-08-08 14:51:40
@Cat_Jack 为啥上来就
by Cat_Jack @ 2024-08-08 14:51:58
@lovely_codecat 谢谢
by lovely_codecat @ 2024-08-08 14:54:26
@Cat_Jack 求关
by mayike @ 2024-08-08 14:59:16
这操作有点秀:
int a = 0,za = 0;
double ansa = za/a;
by Cat_Jack @ 2024-08-08 19:48:12
@lovely_codecat ok
by guoyanwei120223 @ 2024-08-09 17:18:36
#include<bits/stdc++.h>
using namespace std;
int n,k;
double a,b,c,d;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
if(i%k==0)
{
a+=i;
c++;
}
else
{
b+=i;
d++;
}
}
cout<<fixed<<setprecision(1)<<a/c*1.0<<" ";
cout<<fixed<<setprecision(1)<<b/d*1.0;
return 0;
}
这样做,求关