Skip to content

Commit 348de00

Browse files
committed
tc cpp template
1 parent 8ecf968 commit 348de00

File tree

1 file changed

+154
-150
lines changed

1 file changed

+154
-150
lines changed

TopCoder/plugins/CodeTemplate.cpp

Lines changed: 154 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,154 @@
1-
$BEGINCUT$
2-
$PROBLEMDESC$
3-
$ENDCUT$
4-
#include <algorithm>
5-
#include <iostream>
6-
#include <sstream>
7-
#include <string>
8-
#include <vector>
9-
#include <queue>
10-
#include <set>
11-
#include <map>
12-
#include <cstdio>
13-
#include <cstdlib>
14-
#include <cctype>
15-
#include <cmath>
16-
#include <string>
17-
#include <cstring>
18-
using namespace std;
19-
20-
$BEGINCUT$
21-
#define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))
22-
23-
template<typename T> void print( T a ) {
24-
cerr << a;
25-
}
26-
static void print( long long a ) {
27-
cerr << a << "L";
28-
}
29-
static void print( string a ) {
30-
cerr << '"' << a << '"';
31-
}
32-
template<typename T> void print( vector<T> a ) {
33-
cerr << "{";
34-
for ( int i = 0 ; i != a.size() ; i++ ) {
35-
if ( i != 0 ) cerr << ", ";
36-
print( a[i] );
37-
}
38-
cerr << "}" << endl;
39-
}
40-
template<typename T> void eq( int n, T have, T need ) {
41-
if ( have == need ) {
42-
cerr << "Case " << n << " passed." << endl;
43-
} else {
44-
cerr << "Case " << n << " failed: expected ";
45-
print( need );
46-
cerr << " received ";
47-
print( have );
48-
cerr << "." << endl;
49-
}
50-
}
51-
template<typename T> void eq( int n, vector<T> have, vector<T> need ) {
52-
if( have.size() != need.size() ) {
53-
cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements.";
54-
print( have );
55-
print( need );
56-
return;
57-
}
58-
for( int i= 0; i < have.size(); i++ ) {
59-
if( have[i] != need[i] ) {
60-
cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << ".";
61-
print( have );
62-
print( need );
63-
return;
64-
}
65-
}
66-
cerr << "Case " << n << " passed." << endl;
67-
}
68-
static void eq( int n, string have, string need ) {
69-
if ( have == need ) {
70-
cerr << "Case " << n << " passed." << endl;
71-
} else {
72-
cerr << "Case " << n << " failed: expected ";
73-
print( need );
74-
cerr << " received ";
75-
print( have );
76-
cerr << "." << endl;
77-
}
78-
}
79-
$ENDCUT$
80-
81-
#define REP(i,n) for(int i=0;i<(n);++i)
82-
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
83-
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
84-
#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it)
85-
#define CLR(x) memset((x),0,sizeof((x)))
86-
typedef long long LL;
87-
typedef vector<int> VI;
88-
typedef vector<string> VS;
89-
90-
$BEGINCUT$
91-
vector<string> split( const string& s, const string& delim =" " ) {
92-
vector<string> res;
93-
string t;
94-
for ( int i = 0 ; i != s.size() ; i++ ) {
95-
if ( delim.find( s[i] ) != string::npos ) {
96-
if ( !t.empty() ) {
97-
res.push_back( t );
98-
t = "";
99-
}
100-
} else {
101-
t += s[i];
102-
}
103-
}
104-
if ( !t.empty() ) {
105-
res.push_back(t);
106-
}
107-
return res;
108-
}
109-
110-
vector<int> splitInt( const string& s, const string& delim =" " ) {
111-
vector<string> tok = split( s, delim );
112-
vector<int> res;
113-
for ( int i = 0 ; i != tok.size(); i++ )
114-
res.push_back( atoi( tok[i].c_str() ) );
115-
return res;
116-
}
117-
$ENDCUT$
118-
119-
$BEGINCUT$
120-
int s2i(string s) {
121-
stringstream ss;
122-
ss << s;
123-
int res;
124-
ss >> res;
125-
return res;
126-
}
127-
128-
string i2s(int n) {
129-
stringstream ss;
130-
ss << n;
131-
string res;
132-
ss >> res;
133-
return res;
134-
}
135-
$ENDCUT$
136-
137-
class $CLASSNAME$ {
138-
public:
139-
$RC$ $METHODNAME$($METHODPARMS$) {
140-
$RC$ res;
141-
return res;
142-
}
143-
$WRITERCODE$
144-
};
145-
$BEGINCUT$
146-
int main() {
147-
$MAINBODY$
148-
return 0;
149-
}
150-
$ENDCUT$
1+
$BEGINCUT$
2+
$PROBLEMDESC$
3+
$ENDCUT$
4+
#include <algorithm>
5+
#include <iostream>
6+
#include <sstream>
7+
#include <string>
8+
#include <vector>
9+
#include <queue>
10+
#include <set>
11+
#include <map>
12+
#include <cstdio>
13+
#include <cstdlib>
14+
#include <cctype>
15+
#include <cmath>
16+
#include <string>
17+
#include <cstring>
18+
using namespace std;
19+
20+
$BEGINCUT$
21+
#define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))
22+
23+
template<typename T> void print( T a ) {
24+
cerr << a;
25+
}
26+
static void print( long long a ) {
27+
cerr << a << "L";
28+
}
29+
static void print( string a ) {
30+
cerr << '"' << a << '"';
31+
}
32+
template<typename T> void print( vector<T> a ) {
33+
cerr << "{";
34+
for ( int i = 0 ; i != a.size() ; i++ ) {
35+
if ( i != 0 ) cerr << ", ";
36+
print( a[i] );
37+
}
38+
cerr << "}" << endl;
39+
}
40+
template<typename T> void eq( int n, T have, T need ) {
41+
if ( have == need ) {
42+
cerr << "Case " << n << " passed." << endl;
43+
} else {
44+
cerr << "Case " << n << " failed: expected ";
45+
print( need );
46+
cerr << " received ";
47+
print( have );
48+
cerr << "." << endl;
49+
}
50+
}
51+
template<typename T> void eq( int n, vector<T> have, vector<T> need ) {
52+
if( have.size() != need.size() ) {
53+
cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements.";
54+
print( have );
55+
print( need );
56+
return;
57+
}
58+
for( int i= 0; i < have.size(); i++ ) {
59+
if( have[i] != need[i] ) {
60+
cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << ".";
61+
print( have );
62+
print( need );
63+
return;
64+
}
65+
}
66+
cerr << "Case " << n << " passed." << endl;
67+
}
68+
static void eq( int n, string have, string need ) {
69+
if ( have == need ) {
70+
cerr << "Case " << n << " passed." << endl;
71+
} else {
72+
cerr << "Case " << n << " failed: expected ";
73+
print( need );
74+
cerr << " received ";
75+
print( have );
76+
cerr << "." << endl;
77+
}
78+
}
79+
$ENDCUT$
80+
81+
#define REP(i,n) for(int i=0;i<(n);++i)
82+
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
83+
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
84+
#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it)
85+
#define CLR(x) memset((x),0,sizeof((x)))
86+
#define MP make_pair
87+
#define MPI make_pair<int, int>
88+
#define PB push_back
89+
typedef long long LL;
90+
typedef vector<int> VI;
91+
typedef vector<string> VS;
92+
typedef pair<int, int> PI;
93+
94+
$BEGINCUT$
95+
vector<string> split( const string& s, const string& delim =" " ) {
96+
vector<string> res;
97+
string t;
98+
for ( int i = 0 ; i != s.size() ; i++ ) {
99+
if ( delim.find( s[i] ) != string::npos ) {
100+
if ( !t.empty() ) {
101+
res.push_back( t );
102+
t = "";
103+
}
104+
} else {
105+
t += s[i];
106+
}
107+
}
108+
if ( !t.empty() ) {
109+
res.push_back(t);
110+
}
111+
return res;
112+
}
113+
114+
vector<int> splitInt( const string& s, const string& delim =" " ) {
115+
vector<string> tok = split( s, delim );
116+
vector<int> res;
117+
for ( int i = 0 ; i != tok.size(); i++ )
118+
res.push_back( atoi( tok[i].c_str() ) );
119+
return res;
120+
}
121+
$ENDCUT$
122+
123+
$BEGINCUT$
124+
int s2i(string s) {
125+
stringstream ss;
126+
ss << s;
127+
int res;
128+
ss >> res;
129+
return res;
130+
}
131+
132+
string i2s(int n) {
133+
stringstream ss;
134+
ss << n;
135+
string res;
136+
ss >> res;
137+
return res;
138+
}
139+
$ENDCUT$
140+
141+
class $CLASSNAME$ {
142+
public:
143+
$RC$ $METHODNAME$($METHODPARMS$) {
144+
$RC$ res;
145+
return res;
146+
}
147+
$WRITERCODE$
148+
};
149+
$BEGINCUT$
150+
int main() {
151+
$MAINBODY$
152+
return 0;
153+
}
154+
$ENDCUT$

0 commit comments

Comments
 (0)