Taha
2011-06-22 13:09:55 UTC
input format is like this
first line has a number(noppl) which indicates number of people in a group of friends who are going to give each other some gifts.
next noppl lines contain the name of those people
next line contains name of one person followed by a line which contains number of people he is going to buy gift for ("nofriend") and the maximum total amount of money he is going to spend.(money that a person gives or receives must be an integer)
next nofriend lines contain the name of people who are receiving the gifts
next line contains another gift giver name and this goes on until all the names have come.
a sample list is this:
4
david
johnson
charley
nicole
charley
2 67
nicole
johnson
johnson
1 150
nicole
david
3 221
nicole
johnson
charley
nicole
3 5
charley
johnson
david
output is a list of names followed by amount of profit the gift giving has made for them(value of gifts received - value of gifts given)
whenever I run this program it goes non-responding what is the problem?
Also I tried to initialize the array account to 0 but I got an error saying I can't do that because it is variable sized. why is that?
#include
#include
#include
#include
#define maxnlen 14
using namespace std;
int main(){
ifstream fin("gift.in");
ofstream fout("gift.out");
int noppl=7;
if(fin==NULL||fout==NULL)cout<<"can't";
fin>>noppl;
char *pplname[noppl+1];
for(int i=0;i<=noppl-1;i++){
pplname[i]=new char[maxnlen+1];
fin.getline(pplname[i],maxnlen);
}
int account[noppl+1];
char *currentperson;
int nofriend, money;
for(int y=1;y<=noppl;y++){
delete [] currentperson;
currentperson=new char[maxnlen+1];
fin.getline(currentperson,maxnlen);
fin>>nofriend>>money;
int moneyg=int(money/nofriend);
money=moneyg*nofriend;
// this part is to get the number of current person:
int tt=1;
int ttt=0;
while(tt){
if (!strcmp(pplname[ttt],currentperson))
tt=0;
ttt++;
}
ttt--;
//ttt is the number of person
account[ttt]-=money;
for(int j=0; j<=nofriend-1;j++){
delete [] currentperson;
currentperson= new char[maxnlen+1];
fin.getline(currentperson,maxnlen);
// this part is to get the number of current person:
tt=1;
ttt=0;
while(tt){
if (!strcmp(pplname[ttt],currentperson))
tt=0;
ttt++;
}
ttt--;
//**** is the number of person
account[ttt]+=moneyg;
}
}
for(int u=0;u<=noppl-1;u++){
fout<
}
fin.close();
fout.close();
return 0;
}