[Assorted-commits] SF.net SVN: assorted: [825] configs/trunk/src/topcoder/template.cpp
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-05-15 06:27:06
|
Revision: 825 http://assorted.svn.sourceforge.net/assorted/?rev=825&view=rev Author: yangzhang Date: 2008-05-14 23:27:13 -0700 (Wed, 14 May 2008) Log Message: ----------- fixed and enhanced c++ template Modified Paths: -------------- configs/trunk/src/topcoder/template.cpp Modified: configs/trunk/src/topcoder/template.cpp =================================================================== --- configs/trunk/src/topcoder/template.cpp 2008-05-15 00:04:24 UTC (rev 824) +++ configs/trunk/src/topcoder/template.cpp 2008-05-15 06:27:13 UTC (rev 825) @@ -29,9 +29,13 @@ #define pb(x) push_back((x)); #define all(A) (A).begin(), (A).end() #define rall(A) (A).rbegin(), (A).rend() -#define forea(it,xs) for (typeof(xs.begin()) it = xs.begin(); it != xs.end(); it++) -#define FOR(i,xs) for (typeof((xs).size()) i = 0; i < (xs).size(); i++) -#define FOR(i,l,h) for (typeof(l) i = (l); i < (h); i++) +#define each(it,xs) for (typeof(xs.begin()) it = xs.begin(); it != xs.end(); it++) +#define bounds(i,xs) for (typeof((xs).size()) i = 0; i < (xs).size(); i++) +#define range(i,l,h) for (typeof(l) i = (l); i < (h); i++) +#define event(x) { cout << __FILE__ << ":" << __LINE__ << ": " << #x << endl; x; } +#define trace(x) { cout << __FILE__ << ":" << __LINE__ << ": "; pp(x); x; } +#define ping cout << "ping" << endl; +#define pong cout << "pong" << endl; // CHOOSE //int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1}; @@ -44,7 +48,7 @@ typedef vector<vs> vvs; typedef vector<vb> vvb; typedef long long ll; -typedef vector vec; // XXX +#define vec(x) vector< x > typedef string str; template<typename T> inline T mod(T a, T b) { return (a % b + b) % b; } @@ -61,7 +65,8 @@ template<typename T> inline string tos(T x) { stringstream s; s << x; return s.str(); } inline int powi(int a, int b) { return int( std::pow(double(a), double(b)) ); } inline int powl(ll a, ll b) { return ll( std::pow(double(a), double(b)) ); } -template<typename T> inline void pp(const T & x) { cout << x << endl; } +template<typename T> inline void print(const T & x) { cout << x << endl; } +#define pp(x) cout << #x << ' ' << x << endl; inline ll gcd(ll a, ll b) { if (a < 0 && b < 0) return gcd(-a,-b); @@ -76,13 +81,13 @@ template <typename T> inline ostream& operator << (ostream& os, const set<T> & xs) { - FOR(i,xs) os << i ? ", " : "{ " << xs[i]; + bounds(i,xs) os << i ? ", " : "{ " << xs[i]; return os << " }"; } template <typename T> inline ostream& operator << (ostream& os, const vector<T> & xs) { - FOR(i,xs) os << i ? ", " : "{ " << xs[i]; + bounds(i,xs) os << i ? ", " : "{ " << xs[i]; return os << " }"; } @@ -95,14 +100,14 @@ vs split( const string & s, const string & delim = " " ) { vs res; string t; - forea(c,s) { - if ( delim.find( c ) != string::npos ) { + each(c,s) { + if ( delim.find( *c ) != string::npos ) { if ( !t.empty() ) { res.pb( t ); t = ""; } } else { - t += c; + t += *c; } } if ( ! t.empty() ) { @@ -114,10 +119,16 @@ vi ints( const str & s, const str & delim = " " ) { vs ss = split( s, delim ); vi is; - forea(s,ss) is.push_back( atoi( s.c_str() ) ); + each(s,ss) is.push_back( atoi( s->c_str() ) ); return is; } +string vi2str( const vi xs ) { + string s(xs.sz, '\0'); + bounds(i,xs) s[i] = xs[i] + '0'; + return s; +} + // following is needed for 'main' #define ARRSIZE(x) (sizeof(x)/sizeof(x[0])) // $ENDREUSE$ @@ -132,15 +143,15 @@ template<typename T> void print( T a ) { cerr << a; } -static void print( long long a ) { +void print( long long a ) { cerr << a << "L"; } -static void print( string a ) { +void print( string a ) { cerr << '"' << a << '"'; } template<typename T> void print( vector<T> a ) { cerr << "{"; - for ( int i = 0 ; i != a.size() ; i++ ) { + bounds(i,a) { if ( i != 0 ) cerr << ", "; print( a[i] ); } @@ -174,7 +185,7 @@ } cerr << "Case " << n << " passed." << endl; } -static void eq( int n, string have, string need ) { +void eq( int n, string have, string need ) { if ( have == need ) { cerr << "Case " << n << " passed." << endl; } else { @@ -199,6 +210,7 @@ +// asdf class $CLASSNAME$ { public: $RC$ $METHODNAME$($METHODPARMS$) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |