HgSO4_QwQ @ 2021-02-21 12:20:32
#include<iostream>
using namespace std;
int a,k,cnt,ans1,ans2;
int main()
{
cin>>a>>k;
for(int i=1;i<=a;i++)
{
if(i%k==0)
{
ans2+=i;
cnt++;
}
else
{
ans1+=i;
}
}
printf("%.1lf %.1lf",ans1/(a-cnt),ans2/cnt);
return 0;
}
0分
by 渡鸦2007 @ 2021-02-21 12:27:12
@Felder
printf("%.1lf %.1lf",ans1/(a-cnt),ans2/cnt);
改为printf("%.1lf %.1lf",double(ans1)/(a-cnt),double(ans2)/cnt);
by 渡鸦2007 @ 2021-02-21 12:28:27
@fqyz_wyc
你ans
和cnt
都是int类型,相除也是int类型,用%lf
输出会类型错误
by 渡鸦2007 @ 2021-02-21 12:31:07
@Felder
然后`printf`应该用`<cstdio>`库,比赛中`<iostream>`并不包含`printf`
为什么会标记我没按要求使用Md啊
by HgSO4_QwQ @ 2021-02-21 12:32:54
谢谢大佬
by HgSO4_QwQ @ 2021-02-21 12:35:27
??40分
by HgSO4_QwQ @ 2021-02-21 12:37:01
@fqyz_wyc
by 渡鸦2007 @ 2021-02-21 12:38:36
@Felder 你前后输出反了
by HgSO4_QwQ @ 2021-02-21 12:39:00
O
by 渡鸦2007 @ 2021-02-21 12:39:54
@Felder 调整后可过
by HgSO4_QwQ @ 2021-02-21 12:41:06
/tmp/compiler_3aod8zqz/src: 在函数‘int main()’中:
/tmp/compiler_3aod8zqz/src:21:12: 错误:unable to find string literal operator ‘operator""double’ with ‘const char [12]’, ‘long unsigned int’ arguments
printf("%.1lf %.1lf"double(ans2)/cnt,double(ans1)/(a-cnt));
^~~~~~~
?????