USACO 1.1-gift1

/*
ID: m1590291
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream fin ("gift1.in.txt");
    ofstream fout ("gift1.out.txt");
    
    int s,i,j,k,money=0,outnumber=0,num=0;
    string names[12],outname[12];
    int getmoney[12],outmoney[12];
    
    string name1;
    fin >> s;
    for (i=0;i<s;i++)
    {
        getmoney[i]=0;
        outmoney[i]=0;
    }
    for (i=0;i<s;i++) 
		fin >> names[i];
		
    for (i=0;i<s;i++)
    {
        fin >> name1;
        for (j=0;j<s;j++) 
		{
			if (names[j]==name1)
			{
				num=j;
        		fin >> money >> outnumber;
			} 
		}
        if(outnumber!=0)
        {
            for (j=0;j<outnumber;j++)
            {
                fin >> outname[j];
                for (k=0;k<s;k++) 
				{
					if (names[k]==outname[j])
                		getmoney[k]=getmoney[k]+money/outnumber;
            	}
			}
		}
		if (outnumber!=0) 
			outmoney[num]=outmoney[num]+outnumber*(money/outnumber);
	}
    for (i=0;i<s;i++)
    {
        getmoney[i]=getmoney[i]-outmoney[i];
        fout << names[i] << " " << getmoney[i] << endl;
    }
    fin.close();
    fout.close();
    return 0;
}

你可能感兴趣的:(USACO 1.1-gift1)