JXNVCE ALGO-LOG YouJin Jung

GFG DELANNOY NUMBER (RECURSIVE)

#include <bits/stdc++.h>

using namespace std;
 
int dealnnoy(int n, int m) {
    if (m == 0 || n == 0)
        return 1;
 
    return dealnnoy(m - 1, n) + dealnnoy(m - 1, n - 1) + dealnnoy(m, n - 1);
}
 
int main() {
    int n = 3, m = 4;
    cout << dealnnoy(n, m) << endl;
    return 0;
}

GFG MAP PAIRS-STL

#include <bits/stdc++.h>

using namespace std;

map<pair<int, int>, int> vis;

void printPositions(int a[3][3]) {
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			if (vis[{ i, j }] == 0)
				cout << "(" << i << ", " << j << ")" << endl;
}

int main() {
	int mat[3][3] = { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 } };
	vis[{ 0, 0 }] = 1;
	vis[{ 1, 0 }] = 1;
	vis[{ 1, 1 }] = 1;
	vis[{ 2, 2 }] = 1;
	printPositions(mat);
	return 0;
}

GFG FIRST DAY OF WEEK

#include <bits/stdc++.h>

using namespace std;
 
int dayofweek(int d, int m, int y) {
    static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
    y -= m < 3;
    return ( y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
}

int main() {
    int day = dayofweek(30, 8, 2010);
    cout << day;
 
    return 0;
}

GFG CHECK INTEGER OVERFLOW

#include <bits/stdc++.h>

using namespace std;

int addOvf(int* result, int a, int b) {
    *result = a + b;
    if(a > 0 && b > 0 && *result < 0)
        return -1;
    if(a < 0 && b < 0 && *result > 0)
        return -1;
    return 0;
}

int main() {
    int *res = new int[(sizeof(int))];
    int x = 2147483640;
    int y = 10;
 
    cout << addOvf(res, x, y);
 
    cout << endl << *res;
    return 0;
}

GFG PERMUTATION OF STRING

#include <bits/stdc++.h>

using namespace std;
 
void permute(string a, int l, int r) {
    if (l == r)
        cout << a << endl;
    else { 
        for (int i = l; i <= r; i++) {
            swap(a[l], a[i]);
            permute(a, l+1, r);
            swap(a[l], a[i]);
        }
    }
}
 
int main() {
    string str = "ABC";
    int n = str.size();
    permute(str, 0, n-1);
    return 0;
}