[USACO 1.1.2]贪婪的礼物送礼者 (水题又一道)

时间:2022-12-18 13:30:26

题目:http://hustoj.sinaapp.com/problem.php?id=1817

几个人互相送钱,问最后每个人收取的比送出的多多少

又在数据初始化的问题上搞了半天

#include<stdio.h>
#include<string.h>

struct person
{
    char name[15];
    int money;
    int give;
    int get;

}f[11];


int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s",f[i].name);
    }
    for(int i=0;i<n;i++)
    {
        char name[15];
        scanf("%s",name);
        int j;
        for(j=0;j<n;j++)
        {
            if(!strcmp(name,f[j].name)) break;
        }
        int giveout;
        scanf("%d%d",&f[j].money,&giveout);
        int each=0;
        if(f[j].money) each=f[j].money/giveout;
        f[j].give=each*giveout;
        
        char receivename[15]; 
        for(int k=0;k<giveout;k++)
        {
            scanf("%s",receivename);
            int x;
            for(x=0;x<n;x++)
            {
                if(!strcmp(receivename,f[x].name)) break;
            }
            f[x].get+=each;

        }

    
    }

    for(int i=0;i<n;i++)
    {
        int ans=f[i].get-f[i].give;
        printf("%s %d\n",f[i].name,ans);
    }

}