JSK練習-水果店(映射表)

題目鏈接

有關“映射表的映射表”的題目,AC代碼:

#include<bits/stdc++.h>

using namespace std;

set<string>p;
set<string>f;

map<string, map<string, int>>d;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string fr, wh;
        int cnt;
        cin>>fr>>wh>>cnt;
        p.insert(wh);
        f.insert(fr);
        if(!d.count(wh))
            d[wh][fr] = 0;
        else if(!d[wh].count(fr))
            d[wh][fr] = 0;
        d[wh][fr] += cnt;
    }
    for(set<string>::iterator it = p.begin(); it != p.end(); ++it)
    {
        string a = *it;
        cout<<a;
        for(set<string>::iterator itt = f.begin(); itt != f.end(); ++itt)
        {
            if(d[a].count(*itt))
                cout<<"\n"<<" |----"<<*itt<<"("<<d[a][*itt]<<")";
        }
        cout<<endl;
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章