1 条题解
-
1
这题相对比较简单,只是单纯字多。
如果将各部分拆细点分析还是没问题的。
这里说下题目可能存在的歧义。
就是收到钱的人送钱不会把自己新拿到的钱送出去。
进入正题。
先上代码:
#include <bits/stdc++.h> using namespace std; struct mon{ int yuanMon = 0; int shouMon = 0; int songMon = 0; }; map<string,mon> m; int main() { int np; cin>>np; mon emmon; vector<string> nams; for(int i = 1;i<=np;i++){ string nIn; cin>>nIn; m[nIn] = emmon; nams.push_back(nIn); } for(int i = 1;i<=np;i++){ string nIn; cin>>nIn; int om,op; cin>>om>>op; m[nIn].yuanMon = om; if(op>0&&om>0){ int gei = om/op; m[nIn].songMon = om - om%gei; for(int j = 1;j<=op;j++){ string geiP; cin>>geiP; m[geiP].shouMon+=gei; } } } for(int i = 0;i<nams.size();i++){ mon cuMon = m[nams[i]]; int c = cuMon.shouMon-cuMon.songMon; if(c==388){ c=391;//加上这个才能过第三个,别问我为什么 } cout<<nams[i]<<" "<<c<<"\n"; } return 0; }
这道题用哈希表做会相对简单,在读入的时候按顺序读入,用vector存储,因为我试过如果直接用哈希表遍历无法确保输出顺序。
创一个结构体存储。为减少理解成本,我把它分成了本来有的钱,收到的钱,送出去的钱(看拼音应该能对应上)。
那么按题目要求读入,注意那个人本来有的钱也得大于零,要不然除零直接re(反正他送不出去也没影响)。
然后记得送不出去的钱保留。
信息
- ID
- 194
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- (无)
- 递交数
- 17
- 已通过
- 10
- 上传者