USACO 1.1 Greedy Gift Givers
用map,最后输出要按照顺序就先把字符串存起来。
/* ID:zhlc881 LANG:C++ TASK:gift1 */ #include"iostream" #include"stdio.h" #include"string" #include"map" using namespace std; int main() { freopen("gift1.in","r",stdin); freopen("gift1.out","w",stdout); int np,i; map<string,int>mymap; cin>>np; string str[12],s; for(i=0;i<np;i++){ cin >> str[i]; mymap[str[i]]; } for(i=0;i<np;i++){ int a,b; cin>>s>>a>>b; mymap[s]-=a; if(b==0) continue; int tmp=a%b; mymap[s]+=tmp; a/=b; while(b--){ cin>>s; mymap[s]+=a; } } for(i=0;i<np;i++) cout<<str[i]<<" "<<mymap[str[i]]<<endl; return 0; }