# 1.1.2 Greedy Gift Givers　贪婪的送礼者

``````5
dave
laura
owen
vick
amr
dave
200 3
laura
owen
vick
owen
500 1
dave
amr
150 2
vick
owen
laura
0 2
amr
vick
vick
0 0
``````

``````dave 302
laura 66
owen -359
vick 141
amr -150
``````

``````#include"stdio.h"
char name[11][15];
int np;
int check(char s[15])
{
int i,j;
for(j=0;j<np;j++)
{
for(i=0;name[j][i]!='\0'&&s[i]!='\0';i++)
{
if(s[i]!=name[j][i])break;
}
if(s[i]=='\0'&&name[j][i]=='\0')return j;
}
return -1;
}
int main()
{
int i,a[11],m,n,p,avg,b[11];
char s[15];
scanf("%d",&np);
for(i=0;i<np;i++)
{
scanf("%s",name[i]);
a[i]=0;
b[i]=0;
}
for(i=0;i<np;i++)
{
scanf("%s",s);
p=check(s);
scanf("%d %d",&n,&m);
if(m==0)continue;
a[p]=a[p]+n%m;
b[p]=n;
avg=n/m;
while(m--)
{
scanf("%s",s);
p=check(s);
a[p]=a[p]+avg;
}
}
for(i=0;i<np;i++)
printf("%s %d\n",name[i],a[i]-b[i]);
return 0;
}

``````

``````#include <iostream>
using namespace std;
struct Giver
{
string name;
int income;//收入
int expend; //支出
};
Giver gg[11];
int main()
{
int n;
cin>>n;
for(int i = 0;i<n;i++)
cin>>gg[i].name;
for(int i = 0;i<n;i++)
{
string nam;
int x,num;
cin>>nam;
cin>>x>>num;
if(num == 0)
continue;
for(int j = 0;j<n;j++)
{
if(nam==gg[j].name)
gg[j].expend += x/num*num;
}
string exname;
for(int j = 0;j<num;j++)
{
cin>>exname;
for(int k = 0;k<n;k++)
{
if(exname == gg[k].name)
gg[k].income += x/num;
}
}
}
for(int i = 0;i<n;i++)
{
cout<<gg[i].name<<" "<<gg[i].income-gg[i].expend<<endl;
}

return 0;
}
``````