STL中的map
这是usaco section1.1的第一题
#include <fstream>#include <map>using namespace std;ifstream fin("gift1.in");ofstream fout("gift1.out");int main(){ map <string,int> reci,give;//map关联reci give int np,i,j; string names[50]; fin>>np; for(i=0;i<np;i++) fin>>names[i]; for(i=0;i<np;i++) { string temp;//送礼人 int temper,ng;//原有钱数 fin>>temp; fin>>temper>>ng; if (ng) { for (j=0;j<ng;j++) { string tempg; fin>>tempg; reci[tempg]+=temper/ng; give[temp]+=temper/ng; } } } for(i=0;i<np;i++) fout<<names[i]<<" "<<reci[names[i]]-give[names[i]]<<endl; return 0; }