SilverSprite
Mar 2nd, 2003, 11:47 AM
Hey all, i'm having trouble with a problem. I don't know whats wrong with my logic. If anyone could help me, it would be appreciated. Well the problem is in the file attached. The following is my code. Could someone please point out whats wrong?
#include <fstream.h>
#include <string>
#include <math.h>
#include <stdlib.h>
int main()
{
ifstream fin ("gift1.in");
ofstream fout ("gift1.out");
int NP;
fin >> NP;
int splitamount, splitpeople, original[NP];
int gain[NP];
string names [NP];
string host, person;
for (int i=0; i<NP; i++)
{
fin >> names[i];
gain[i]=0;
}
for (int j=0; j<NP; j++)
{
fin >> host >> splitamount >> splitpeople;
for (int i=0; i<NP; i++)
if (names[i] == host)
{
original [i] = splitamount;
if (splitpeople != 0)
gain[j] += (splitamount % splitpeople);
else
gain[j] = splitamount;
}
for (int i=0; i<splitpeople; i++)
{
fin >> person;
for (int k=0; k<NP; k++)
if (names[k] == person)
gain[k] += static_cast<int>(floor(splitamount/splitpeople));
}
}
for (int i=0; i<NP; i++)
fout << names[i] << " " << gain[i]-original[i] << endl;
return 0;
}
#include <fstream.h>
#include <string>
#include <math.h>
#include <stdlib.h>
int main()
{
ifstream fin ("gift1.in");
ofstream fout ("gift1.out");
int NP;
fin >> NP;
int splitamount, splitpeople, original[NP];
int gain[NP];
string names [NP];
string host, person;
for (int i=0; i<NP; i++)
{
fin >> names[i];
gain[i]=0;
}
for (int j=0; j<NP; j++)
{
fin >> host >> splitamount >> splitpeople;
for (int i=0; i<NP; i++)
if (names[i] == host)
{
original [i] = splitamount;
if (splitpeople != 0)
gain[j] += (splitamount % splitpeople);
else
gain[j] = splitamount;
}
for (int i=0; i<splitpeople; i++)
{
fin >> person;
for (int k=0; k<NP; k++)
if (names[k] == person)
gain[k] += static_cast<int>(floor(splitamount/splitpeople));
}
}
for (int i=0; i<NP; i++)
fout << names[i] << " " << gain[i]-original[i] << endl;
return 0;
}