Skip to content

Commit 59312a6

Browse files
committed
template demo.cpp so that others can understand my template
1 parent 8be81ef commit 59312a6

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
#define gc getchar_unlocked
4+
#define fo(i,n) for(i=0;i<n;i++)
5+
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
6+
#define ll long long
7+
#define si(x) scanf("%d",&x)
8+
#define sl(x) scanf("%lld",&x)
9+
#define ss(s) scanf("%s",s)
10+
#define pi(x) printf("%d\n",x)
11+
#define pl(x) printf("%lld\n",x)
12+
#define ps(s) printf("%s\n",s)
13+
#define deb(x) cout << #x << "=" << x << endl
14+
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
15+
#define pb push_back
16+
#define mp make_pair
17+
#define F first
18+
#define S second
19+
#define all(x) x.begin(), x.end()
20+
#define clr(x) memset(x, 0, sizeof(x))
21+
#define sortall(x) sort(all(x))
22+
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
23+
#define PI 3.1415926535897932384626
24+
typedef pair<int, int> pii;
25+
typedef pair<ll, ll> pl;
26+
typedef vector<int> vi;
27+
typedef vector<ll> vl;
28+
typedef vector<pii> vpii;
29+
typedef vector<pl> vpl;
30+
typedef vector<vi> vvi;
31+
typedef vector<vl> vvl;
32+
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
33+
int rng(int lim) {
34+
uniform_int_distribution<int> uid(0,lim-1);
35+
return uid(rang);
36+
}
37+
int mpow(int base, int exp);
38+
void ipgraph(int m);
39+
void dfs(int u, int par);
40+
41+
const int mod = 1'000'000'007;
42+
const int N = 300, M = N;
43+
//=======================
44+
45+
vi g[N];
46+
int a[N][M];
47+
48+
void solve() {
49+
int i, j, n, m;
50+
int x = 0;
51+
52+
si(n);
53+
deb(n); // debug a variable easily 😉
54+
55+
// fo demo
56+
{
57+
for(i=0; i < n; i++)
58+
for(j=0; j < n; j++)
59+
si(a[i][j]);
60+
61+
// print sum
62+
int sum = 0;
63+
fo(i, n) fo(j, n) sum += a[i][j];
64+
pi(sum);
65+
}
66+
67+
// Fo demo - works in both direction (0 to 100) as well as (100, 0)
68+
{
69+
fo(i, n) {
70+
Fo(j, n-1, -1) printf("%d ", a[i][j]);
71+
printf("\n");
72+
}
73+
}
74+
75+
76+
// modulo
77+
{
78+
// (a * b) % mod == ( (a%mod) * (b%mod) ) % mod
79+
int mpow_result = mpow(2, 1000);
80+
pi(mpow_result);
81+
}
82+
}
83+
84+
int main() {
85+
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
86+
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
87+
88+
int t = 1;
89+
// cin >> t;
90+
deb(t);
91+
92+
while(t--) {
93+
solve();
94+
}
95+
96+
return 0;
97+
}
98+
99+
int mpow(int base, int exp) {
100+
base %= mod;
101+
int result = 1;
102+
while (exp > 0) {
103+
if (exp & 1) result = ((ll)result * base) % mod;
104+
base = ((ll)base * base) % mod;
105+
exp >>= 1;
106+
}
107+
return result;
108+
}
109+
110+
void ipgraph(int n, int m){
111+
int i, u, v;
112+
while(m--){
113+
cin>>u>>v;
114+
g[u-1].pb(v-1);
115+
g[v-1].pb(u-1);
116+
}
117+
}
118+
119+
void dfs(int u, int par){
120+
for(int v:g[u]){
121+
if (v == par) continue;
122+
dfs(v, u);
123+
}
124+
}
125+
126+

0 commit comments

Comments
 (0)