usaco 1.11

/*
ID: liu21781
LANG: C
TASK: gift1
*/

#include"stdio.h"
#include"string.h"
struct student
{
char name[15];
int sum,n,s;
}pe[10];

int main( )
{
FILE *fin = fopen ("gift1.in", "r");
FILE *fout = fopen ("gift1.out", "w");
int i,j,k,m,v;
char ab[15],ac[15];
while(fscanf(fin,"%d",&m)==1)
{
for(i=0;i<m;i++)
{
fscanf(fin,"%s",pe[i].name);
pe[i].s=0;
}
for(i=0;i<m;i++)
{
fscanf(fin,"%s",ab);
for(j=0;j<m;j++)
if(!strcmp(ab,pe[j].name))
break;
fscanf(fin,"%d%d",&pe[j].sum,&pe[j].n);
for(k=0;k<pe[j].n;k++)
{
fscanf(fin,"%s",ac);
for(v=0;v<m;v++)
if(!strcmp(ac,pe[v].name))
{
pe[v].s+=pe[j].sum/pe[j].n;
break;
}
}
if(pe[j].n!=0)
pe[j].s+=pe[j].sum%pe[j].n;
else
pe[j].s+=pe[j].sum;

}
for(i=0;i<m;i++)
fprintf(fout,"%s %d\n",pe[i].name,pe[i].s-pe[i].sum);
}
return 0;
}

 

你可能感兴趣的:(USACO)