cjcjcjminecraft @ 2024-06-02 20:50:02
3篇代码如下: re1:
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int sum1=0,sum2=0,n,k;
scanf("%d %d",n,k);
for(int i=1;i<=n;i++){
if(i%k==0){
sum1+=i;
}
else{
sum2+=i;
}
}
printf("%.1lf %.1lf",sum1/n,sum2/n);
return 0;
}
re2:
#include<iostream>
#include<iomanip>
#include<cstdio>
using namespace std;
int main(){
int sum1=0,sum2=0,n,k;
scanf("%d %d",n,k);
for(int i=1;i<=n;i++){
if(i%k==0){
sum1+=i;
}
else{
sum2+=i;
}
}
//printf("%.1lf %.1lf",sum1/n,sum2/n);
cout<<fixed<<setprecision(1)<<sum1/n<<" "<<fixed<<setprecision(1)<<sum2/n;
return 0;
}
wa:
#include<iostream>
#include<iomanip>
#include<cstdio>
using namespace std;
int main(){
long long sum1=0,sum2=0,n,k;
//scanf("%d %d",n,k);
cin>>n>>k;
for(int i=1;i<=n;i++){
if(i%k==0){
sum1+=i;
}
else{
sum2+=i;
}
}
//printf("%.1lf %.1lf",sum1/n,sum2/n);
cout<<fixed<<setprecision(1)<<sum1/n<<" "<<fixed<<setprecision(1)<<sum2/n;
return 0;
}
真服了... 求改
by 2345A @ 2024-06-02 20:54:45
@cjcjcjminecraft
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n, k, a=0, b=0 ;
double u=0,v=0;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
if (i % k == 0)
{
a =a+i;
u++;
}
else if (i % k != 0)
{
b=b+i;
v++;
}
}
cout << fixed << setprecision(1) << a/u<<" "<<b/v;
return 0;
}
by 2345A @ 2024-06-02 20:55:18
@cjcjcjminecraft 有可能有浮点数(小数)吧