全RE求

P5719 【深基4.例3】分类平均

Mxolq_Icb @ 2023-02-03 21:41:14

#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{//sqrt- pow+ fixed<<setprecision(num)/
    int n,k,a[10001],b[10001],count1=0,count2=0,sum1,sum2;
    double ans1,ans2;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        if(i%k==0){//a
            i=a[count1];
            count1++;
        }else{//b
            i=b[count2];
            count2++;
        }
    }
    //////////////////////////
    for(int i=1;i<=count1;i++){
        sum1+=a[i];
    }
    for(int i=1;i<=count2;i++){
        sum2+=b[i];
    }
    ans1=sum1/count1;ans2=sum2/count2;
    cout<<fixed<<setprecision(1)<<ans1;
    cout<<fixed<<setprecision(1)<<ans2;
    return 0;
}

by ____someone____ @ 2023-02-04 00:45:06

#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,a[10001],b[10001];
    int count1=0,count2=0;
    double sum1=0,sum2=0;
    double ans1,ans2;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        if(i%k==0){
            a[count1]=i;
            count1++;
        }else{
            b[count2]=i;
            count2++;
        }
    }
    for(int i=0;i<count1;i++){
        sum1+=a[i];
    }
    for(int i=0;i<count2;i++){
        sum2+=b[i];
    }
 //   cout<<sum1<<endl<<count1<<endl<<sum2<<endl<<count2<<endl;
    ans1=double(sum1/count1);ans2=double(sum2/count2);
    cout<<fixed<<setprecision(1)<<ans1<<endl;
    cout<<fixed<<setprecision(1)<<ans2;
    return 0;
}

@Mxolq_Icb


by ____someone____ @ 2023-02-04 00:47:06

@Mxolq_Icb 我那个代码输出格式没改,你改一下,把换行改成空格,不然还会 WA


上一页 |