TopCoder High School SRM 39 Level one - 250 pt - Web Browser editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm39
TopCoder High School SRM 39 Level one - 250 pt - Web Browser solution:
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> using namespace std; #define forn(i,n) for(int i=0; i<int((n)); ++i) #define forv(i,v) forn(i,int(v.size())) #define ALL(a) (a).begin(),(a).end() #define pb push_back #define sz size() #define SORT(a) sort(ALL(a)) #define iss istringstream typedef vector< int > vi; typedef vector< string > vs; class WebBrowser { public: vector <string> getSequence(vector <string> a) { vector <string> ans; vs back; vs forw; string cur; forv (i,a) { if ( a[i] == "BACK" ) { if ( back.sz != 0 ) { if ( cur != "" ) forw.insert(forw.begin(),cur);//,cur); cur = back[back.sz-1]; back.erase(back.end()-1); ans.pb(cur); } } else if ( a[i] == "FORWARD" ) { if ( forw.sz > 0 ) { if ( cur != "" ) back.pb(cur); cur = forw[0]; forw.erase(forw.begin()); ans.pb(cur); } } else { if ( cur != a[i] ) { if ( cur != "" ) back.pb(cur); cur = a[i]; forw.clear(); ans.pb(cur); } } } return ans; } };
No comments:
Post a Comment