Hello friends, Today I'm sharing some contest templates created by World Class Coders, I will add some more and I'm creating one for C++ as well. You should use this during competitions it will really help and increase your speed, you don't have to type too much..
For C++...
Created by Zobayer
For C++...
Created by Zobayer
#include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <iostream> #include <sstream> #include <iomanip> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #include <iterator> #include <utility> using namespace std; template< class T > T _abs(T n) { return (n < 0 ? -n : n); } template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); } template< class T > T _min(T a, T b) { return (a < b ? a : b); } template< class T > T sq(T x) { return x * x; } template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); } template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; } template< class T > void setmax(T &a, T b) { if(a < b) a = b; } template< class T > void setmin(T &a, T b) { if(b < a) a = b; } #define MP(x, y) make_pair(x, y) #define REV(s, e) reverse(s, e) #define SET(p) memset(p, -1, sizeof(p)) #define CLR(p) memset(p, 0, sizeof(p)) #define MEM(p, v) memset(p, v, sizeof(p)) #define CPY(d, s) memcpy(d, s, sizeof(s)) #define READ(f) freopen(f, "r", stdin) #define WRITE(f) freopen(f, "w", stdout) #define ALL(c) c.begin(), c.end() #define SIZE(c) (int)c.size() #define PB(x) push_back(x) #define ff first #define ss second #define i64 __int64 #define ld long double #define pii pair< int, int > #define psi pair< string, int > const double EPS = 1e-9; const double BIG = 1e19; const int INF = 0x7f7f7f7f; int main() {
//READ("in.txt"); //WRITE("out.txt"); return 0; }
For Java....Created by Petr
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Comparator;
class ProgramName {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
int testCount = Integer.parseInt(in.next());
/* yoour code here*/
out.close();
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public char readCharacter() {
int c = read();
while (isSpaceChar(c))
c = read();
return (char) c;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void printLine(long i) {
writer.println(i);
}
}
class IOUtils {
public static char[] readCharArray(InputReader in, int size) {
char[] array = new char[size];
for (int i = 0; i < size; i++)
array[i] = in.readCharacter();
return array;
}
}
class ArrayUtils {
public static int count(char[] array, char value) {
int result = 0;
for (char i : array) {
if (i == value)
result++;
}
return result;
}
}
And here some faster I/O methods that you can use during large number of inputs...
1.
inline int scan_f( int *location)
{ register int digit;
register int result = 0;
while( (digit = getchar()) >= '0')
result = (result << 3) + (result << 1) + digit - '0';
*location = result;
return 0; }
//for scanning scan_f(&t);
2.
2. inline int inp() {
int n=0;
char p=getchar_unlocked();
while((p<'0'||p>'9')&&p!=EOF)
p=getchar_unlocked();
while(p>='0'&&p<='9')
{
n = (n<< 3) + (n<< 1) + (p - '0');
p=getchar_unlocked();}
return n;}
For Scanning int n; n = inp();
3.
char ibuf[BUF];
int ipt = BUF;
//Global declaration
int readInt() {
while (ipt < BUF && ibuf[ipt] < '0') ipt++;
if (ipt == BUF) {
fread(ibuf, 1, BUF, stdin);
ipt = 0;
while (ipt < BUF && ibuf[ipt] < '0') ipt++;
}
int n = 0;
while (ipt < BUF && ibuf[ipt] >= '0') n = (n*10)+(ibuf[ipt++]-'0');
if (ipt == BUF) {
fread(ibuf, 1, BUF, stdin);
ipt = 0;
while (ipt < BUF && ibuf[ipt] >= '0') n = (n*10)+(ibuf[ipt++]-'0');
}
return n;
}
I hope this will really help you....any errors or suggestions please comment below!
Happy Coding!! Enjoy! :D
Post A Comment:
0 comments: