TopCoder High School SRM 31 Level one - 250 pt - Traffic Report editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm31
TopCoder High School SRM 31 Level one - 250 pt - Traffic Report solution:
#include <iostream> #include <vector> #include <sstream> #include <map> using namespace std; class TrafficReport { public: int bestRoute(vector <string> ro, vector <string> re) { string c; int b, ans=0; map <string, int> a, d; for(int i=0; i<ro.size(); i++) { stringstream e(ro[i]); while(e>>b>>c) a[c]=b, ans+=b; } for(int i=0; i<re.size(); i++) { stringstream f(re[i]); while(f>>b>>c) if(a.count(c)) ans+=b; } return ans; } };
note: use count() function from <map> to find specific thing you are looking for: http://www.cplusplus.com/reference/map/map/count/
size_type count (const key_type& k) const;
Count elements with a specific key
No comments:
Post a Comment