wenjie1213 @ 2021-09-28 19:55:42
#include<stdio.h>
#include<math.h>
int main() {
int n, k;
printf("请输入n和k的值:");
scanf("%d %d", &n, &k);
float sum1=0, sum2=0;
float fre= 0;
for (int i = 1; i <= n; i++) {
if (i % k == 0) {
sum1 += i;
fre++;
}
else
sum2 += i;
}
sum1 = sum1 / fre;
sum2 = sum2 / (n-fre);
printf("%.1f %.1f", sum1, sum2);
return 0;
}```
by KonJAC_xrs @ 2021-09-28 19:57:56
giegie你把第一个printf删掉吧qwq
by Loser_King @ 2021-09-28 19:57:56
printf("请输入n和k的值:");
这是算法竞赛,不是工程。
输入友好的提示性语言不但不会加分,还会得到 Wrong Answer
的结果。
by wenjie1213 @ 2021-09-28 20:04:14
@xrs蒟蒻 删了但只有40分
by wenjie1213 @ 2021-09-28 20:06:43
@Loser_King 明白了 感谢提醒
by KonJAC_xrs @ 2021-09-28 20:16:57
@wenjie1213 把float改成double就好啦(以后直接用double就行qwq)
by Loser_King @ 2021-09-28 20:18:37
C++ 中 float
精度低于 double
by wenjie1213 @ 2021-09-28 22:09:57
@xrs蒟蒻 已经解决了 阿里嘎多