Skip to content

Instantly share code, notes, and snippets.

@jishanshaikh4
Created April 9, 2022 13:33
Show Gist options
  • Save jishanshaikh4/fc5b1b564dfed809ebba826936ab4511 to your computer and use it in GitHub Desktop.
Save jishanshaikh4/fc5b1b564dfed809ebba826936ab4511 to your computer and use it in GitHub Desktop.
A general code template for programming contests with implementations of commonly used functions
// DATE: @DATE
// Code *NAME_HERE* prepared for *auction* by Jishan Shaikh via template.
// To be run by C++14 GCC/CLANG/MSVS compiler, (maybe) not compatible for C++11
// Last updated: December 17, 2018 (https://github.com/jishanshaikh4/cpp14-template/commit/63b8aa993ae58d62ea3cb467a398692f3aad9117)
// Works on most of the competitions platforms with minor tweaks
#include <bits/stdc++.h>
#define mod 1000000007
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define mp(x, y) make_pair(x, y)
#define f first
#define s second
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define sdl(x) scanf("%lld", &x)
#define sdl2(x, y) scanf("%lld%lld", &x, &y)
#define sdl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pb(x) push_back(x)
#define endl "\n"
#define gc getchar_unlocked
#ifndef getchar_unlocked
#define getchar_unlocked getchar
#endif
using namespace std;
string inttostr(ll str) {
stringstream stream;
stream << str;
return stream.str();
}
ll modexpo(ll a,ll b,ll n) {
ll d = 1;
while(b) {
if(b & 1)
d = (d*a) % n;
b >>= 1;
a = (a*a) % n;
}
return d;
}
ll expo(ll a, ll b) {
ll d = 1;
while(b) {
if(b & 1)
d *= a;
b >>= 1;
a *= a;
}
return d;
}
ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b) {
return (a * b) / gcd(a, b);
}
ll inv(ll a, ll m) {
return modexpo(a, m-2, m);
}
void parr(ll a[], ll n) {
for(int i=0; i<n; i++)
cout << a[i] << " ";
cout << endl;
}
template <typename T>
void gi(T &r) {
r = 0;
char input = gc();
int kl = 1;
while(input < '0' || input > '9') {
if(input == '-')
kl = -1;
input = gc();
}
while('0' <= input && input <= '9')
r = (r << 3) + (r << 1) + (input - '0'), input = gc();
if(kl < 1)
r = -r;
}
void gs(string &r) {
r.clear();
char input = gc();
while(!isgraph(input))
input = gc();
while(isgraph(input)) {
r.push_back(input);
input = gc();
}
}
signed main() {
fastio();
int i = 0, j = 0, k = 0;
string s = "";
gi(i);
gi(j);
gi(k);
gs(s);
cout << i << endl << j << endl << k << endl;
cout << s;
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
vector <int> arr(n, 0);
for(int i = 0; i < n; i++)
cin >> arr[i];
for(int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment