close

題目連結:  https://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=2311

題目大意:  很單純的記帳問題, 給你人名,計算金流

思路: STL map 紀錄哪個人花多少錢, 最後原本題目輸入順序輸出。 完全不懂這題為甚麼是dp

代碼: 

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    string name[11], man;
    while(cin >> n){
        unordered_map<string, int> mp;
        for(int i = 0; i < n; ++i){
            cin >> name[i];
            mp[name[i]] = 0;
        }
        int cost, num;
        while(cin >> man, man != "0"){
            cin >> cost >> num;
            mp[man] -= cost;
            for(int i = 0; i < num; ++i){
                cin >> man;
                mp[man] += (cost/num);
            }
        }
        for(int i = 0; i < n; ++i)
            cout << name[i] << " " << mp[name[i]] << endl;
    }

    return 0;
}
/*
6
tom mary joe david steve gary
tom 400 2 mary steve
mary 120 3 joe david tom
0
*/

arrow
arrow
    創作者介紹
    創作者 尾玉 的頭像
    尾玉

    louisfghbvc的部落格

    尾玉 發表在 痞客邦 留言(0) 人氣()