gpt4 book ai didi

c++ - Greedy Gift Givers USACO 培训计划中的执行错误

转载 作者:行者123 更新时间:2023-11-28 06:30:40 27 4
gpt4 key购买 nike

<分区>

我今年在高中上计算机编码课,我正在尝试做 Greedy Gift Givers( http://cerberus.delosent.com:791/usacoprob2?a=2uhftHpQUHa&S=gift1 )。我将其上交并收到执行错误:

"Execution error: Your program did not produce an answer that was judged as correct. The program stopped at 0.005 seconds; it used 3496 KB of memory. Your answer length was 119; the correct length is 121. At character number 21, your answer says '1' while the correct answer says '5'."

我快完成了,它给出了十分之四的正确答案。我不知道如何解决它。我的一位 friend 告诉我检查我的变量,我照做了,但据我所知,所有这些都是正确的。

新代码如下:

/*
ID : aknorth1
PROB : gift1
LANG : C++
*/

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
const int ARRAY_SIZE=10;

int groupSize, numReceivers, giveAway;
int bankAcct[ARRAY_SIZE];
string giver, receivers;
string groupPeople[ARRAY_SIZE];

ofstream fout ("gift1.out");
ifstream fin ("gift1.in");

fin >> groupSize;

for (int j=0; j<groupSize; j++)
{
fin >> groupPeople[j];
bankAcct[j]=0;
}

for(int x=0; x<groupSize; x++)
{
fin >> giver;
fin >> giveAway;
fin >> numReceivers;
for (int j=0; j<numReceivers; j++)
{
if (giver == groupPeople[j])
{
bankAcct[j] -= giveAway;
if (numReceivers != 0)
{
bankAcct[j] += (giveAway % numReceivers);
}
}
}
for(int j=0; j<numReceivers; j++)
{
fin >> receivers;

for (int q=0; q<groupSize; q++)
if (groupPeople[q] == receivers)
{
if (numReceivers != 0)
{
bankAcct[q] += (giveAway / numReceivers);
}
}
}
}
for (int j=0; j<groupSize; j++)
{
fout << groupPeople[j]<< " " << bankAcct[j] << endl;
}
return 0;
}

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