2008-12-29
SRM384 Div1 Easy: Library
簡単。split()は自前
#define sz(a) int((a).size()) #define pb push_back #define all(c) (c).begin(),(c).end() #define tr(c,i) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define rep(var,n) for(int var=0;var<(n);var++) #define found(s,e) ((s).find(e)!=(s).end()) class Library { public: int documentAccess(vector<string> records, vector<string> userGroups, vector<string> roomRights) { map<string,int> ug, rr; int Nug=sz(userGroups), Nrr=sz(roomRights); rep(i,Nug) ug[userGroups[i]] = i; rep(i,Nrr) rr[roomRights[i]] = i; set<string> books; tr(records,it){ vector<string> rec = split(*it); if (!found(ug,rec[2])) continue; if (!found(rr,rec[1])) continue; books.insert(rec[0]); } return books.size(); } };