yezhanfeng @ 2024-12-18 22:44:39
using namespace std; int main() { int n,k; cin>>n>>k; double counta=0,countb=0,cnta=0,cntb=0; for(int i=1;i<=n;i++) { if(i%k==0) { counta++; cnta+=i; } else { countb++; cntb+=i; } } double pja,pjb; pja=cnta/counta; pjb=cntb/countb; cout<<pja<<" "<<pjb; return 0; }
by hepingge10 @ 2024-12-18 22:56:55
注意题目说保留一位小数, 要用iomanip库的setprecision(n)函数或者printf里的“.nlf”的控制位数
#include<iomanip>
cout << setprecision(1) << 输出 << endl;
#include<stdio.h>
printf("%.1f %.1f",答案1,答案2);