gpt4 book ai didi

c - 该程序的输出未被接受

转载 作者:行者123 更新时间:2023-11-30 17:09:22 25 4
gpt4 key购买 nike

我正在尝试提交在 codechef“https://www.codechef.com/problems/FLOW009 ”上给出的答案这是我的代码。

#include <stdio.h>
int main()
{
int t, i;
scanf("%d",&t);
i=t;
float qty[t], per[t], sum[t];
do{
scanf("%f %f", &qty[t-1], &per[t-1]);
sum[t-1] = qty[t-1] * per[t-1];
if(qty[t-1] > 1000 )
{
sum[t-1] = sum[t-1] - (sum[t-1]*10)/100;
}
}while(--t);
do{
printf("%f\n", sum[i-1]);
}while(--i);
return 0;
}

它再次告诉我,我的解决方案是错误的,我无法理解它。我不能在那里提问,因为我的业力较小。

最佳答案

有两件事:

  1. 在被告知之前切勿存储每个测试用例的值,因为有时测试用例可能很大,就地计算并打印每个测试用例的输出。这可以节省内存、时间并减少困惑。

  2. 几行代码就可以完成的事情为什么要处理太多代码和困惑。

看这个:

#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int p,q;
scanf("%d %d",&q,&p);
float ans=(float)q*p;
if(q>1000)
ans-=(ans/10);
printf("%f\n",ans);
}
return 0;
}

关于c - 该程序的输出未被接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33319935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com