First, does anyone have sample input/output for this problem?
My question is, do i have to take in all the input at once? Or can I just take one group and print out the result, then take the next group?
Here is my WA C++ code:
Code: Select all
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char people[10][10];
char temp[12];
int netGain[10];
int numGroup, numSubGroup, moneySpent;
while(cin >> numGroup) //get the total number of people in the group
{
for(int x = 0; x < 10; x++)
{
netGain[x] = 0;
}
for(int x = 0; x < numGroup; x++) //set the people's name into the array people[]
{
cin >> people[x];
}
for(int z = 0; z < numGroup; z++)
{
cin >> temp >> moneySpent >> numSubGroup; //get the first line
if(moneySpent != 0)
{
for(int x = 0; x < numGroup; x++) //find out person the line corresponds to
{
if(strcmp(temp,people[x]) == 0)
{
if(numSubGroup != 0)
{
netGain[x] -= moneySpent;
netGain[x] += moneySpent%numSubGroup;
break;
}
}
}
}
if(numSubGroup != 0)
{
for(int x = 0; x < numSubGroup; x++)
{
cin >> temp;
if(moneySpent != 0)
{
for(int y = 0; y < numGroup; y++)
{
if(strcmp(temp,people[y]) == 0)
{
netGain[y] += moneySpent/numSubGroup;
break;
}
}
}
}
}
}
for(int x = 0; x < numGroup; x++)
{
cout << people[x] << " " << netGain[x] << endl;
}
cout << "\n";
}
return 0;
}
Please help, I would appreciate it!