1. Master Header File
#include <bits/stdc++.h>
2. Faster I/O Operations
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
3. Macros for Debugging
#define deb(x) cout << #x << " : " << x << "\n"
4. Number of Digits
int number = 12345;
int digits = floor(log10(number) + 1); // 5
5. Swap Two Numbers
int a = 10;
int b = 20;
swap(a, b); // 20 10
6. Number of Set Bits
int n = 15;
int setBit = __builtin_popcount(n); // 4
7. Auto Keyword
vector<int> v{1, 2, 3, 4, 5};
for (auto x : v)
cout << x << " "; // 1 2 3 4 5
8. Inbuilt GCD Function
int x = 12;
int y = 16;
int gcd = __gcd(x, y); // 4
9. Lambda Function
auto add = [](int x, int y) {
return x + y;
};
int sum = add(10, 20); // 30
10. Accumulate Function
int sum = 10;
int arr[] = {20, 30, 40};
sum = accumulate(arr, arr + 3, sum); // 100
Tip: Use “\n” instead of endl;
Mentoring people how to make better career and live the life at fullest. Software Developer.
3 年good information
SDE-2 @JP Morgan Chase & Co. || Freelancer || Former - SDE Intern : Animall, Zorp || Frontend Web Developer || Documenting Software Development
3 年Informative!