/*
ID: sdjllyh1
PROG: gift1
LANG: C++
TIME: 2008/9/7
*/


//#include "stdafx.h"
#include <iostream>
#include 
<fstream>
#include 
<string>
#include 
<vector>
using namespace std;

class PEOPLE
{
private:
    
string m_name;
    
int m_giveMoney;
    
int m_receiveMoney;

public:
    PEOPLE(
string name)
    
{
        m_name 
= name;
        m_giveMoney 
= 0;
        m_receiveMoney 
= 0;
    }

    
void SetGiveMoney(int giveMoney)
    
{
        m_giveMoney 
= giveMoney;
    }

    
void AddReceiveMoney(int receiveMoney)
    
{
        m_receiveMoney 
+= receiveMoney;
    }

    
string GetName()
    
{
        
return m_name;
    }

    
int GetDifference()
    
{
        
return m_receiveMoney - m_giveMoney;
    }


}
;


vector
<PEOPLE> people;

int n;

int FindNumber(string name)
{
    
int retNum = 0;
    
for(int i=0; i<n; i++)
    
{
        
if(people[i].GetName() == name)
        
{
            retNum 
= i;
            
break;
        }

    }

    
return retNum;
}


int main() {
    ofstream fout (
"gift1.out");
    ifstream fin (
"gift1.in");
    
    fin
>>n;
    
string name;
    
for(int i=0; i<n; i++)
    
{
        fin
>>name;
        PEOPLE newPeople(name);
        people.push_back(newPeople);
    }


    
for(int i=0; i<n; i++)
    
{
        
string giver;
        
int hasMoney;
        
int receiverCount;
        fin
>>giver>>hasMoney>>receiverCount;
        
if(receiverCount > 0)
        
{
            
int num = FindNumber(giver);
            
int giveMoney = ((int)(hasMoney / receiverCount)) * receiverCount;
            people[num].SetGiveMoney(giveMoney);
            
            
for(int j=0; j<receiverCount; j++)
            
{
                
string receiverName;
                fin
>>receiverName;
                
int receiverNum = FindNumber(receiverName);
                people[receiverNum].AddReceiveMoney(hasMoney 
/ receiverCount);
            }

        }

    }


    
//show
    for(int i=0; i<n; i++)
    
{
        fout
<<people[i].GetName()<<' '<<people[i].GetDifference()<<endl;
    }


    
return 0;
}



posted on 2008-09-07 16:51  刘永辉  阅读(406)  评论(0编辑  收藏  举报