JXNVCE ALGO-LOG YouJin Jung

GFG FIND EXCEL COLUMN NAME FROM GIVEN COLUMN NUMBER

#include <bits/stdc++.h>
#define MAX 50

using namespace std;

void printString(int n) {
    char str[MAX];
    int i = 0;

    while (n > 0) {
        int rem = n % 26;

        if (rem == 0) {
            str[i++] = 'Z';
            n = (n / 26) - 1;
        }
        else {
            str[i++] = (rem - 1) + 'A';
            n = n / 26;
        }
    }
    str[i] = '\0';
    reverse(str, str + strlen(str));
    cout << str << endl;
 
    return;
}
 
int main() {
    printString(26);
    printString(51);
    printString(52);
    printString(80);
    printString(676);
    printString(702);
    printString(705);
    return 0;
}

BOJ-1105

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
using namespace std;

int main() {
	ios::sync_with_stdio(false); 
        cin.tie(NULL); cout.tie(NULL);
	string a, b;
        cin >> a >> b;
	if (a.length() != b.length()) {
		cout << 0;
		return 0;
	}

	int count = 0;
	for (int i = 0; i < a.length(); i++) {
		if (a[i] == b[i] && a[i] == '8')
			count++;
		else if (a[i] != b[i])
			break;
	}
	cout << cnt;
	return 0;
}

GFG NEXT POWER OF TWO

#include <bits/stdc++.h>
using namespace std;
 
unsigned int nextPowerOf2(unsigned int n) {
    unsigned count = 0;
    if (n && !(n & (n - 1)))
        return n;
     
    while( n != 0) {
        n >>= 1;
        count += 1;
    }
     
    return 1 << count;
}
 
int main() {
    unsigned int n = 0;
    cout << nextPowerOf2(n);
    return 0;
}

GFG RUSSIAN PEASANT

#include <iostream>
using namespace std;
 
// A method to multiply two numbers using Russian Peasant method
unsigned int russianPeasant(unsigned int a, unsigned int b) {
    int res = 0;
    while (b > 0) {
        if (b & 1)
            res = res + a;
        a = a << 1;
        b = b >> 1;
    }
    return res;
}
 
int main() {
    cout << russianPeasant(18, 1) << endl;
    cout << russianPeasant(20, 12) << endl;
    return 0;
}

GFG NON DECREASING NUMBERS OF N DIGITS

#include<bits/stdc++.h>

using namespace std;
 
long long int countNonDecreasing(int n) {
    memset(dp, 0, sizeof dp);

    for (int i = 0; i < 10; i++)
        dp[i][1] = 1;
 
    // Fill the table in bottom-up manner
    for (int digit = 0; digit <= 9; digit++) {
        for (int len = 2; len <= n; len++) {
            for (int x = 0; x <= digit; x++)
                dp[digit][len] += dp[x][len-1];
        }
    }
 
    long long int count = 0;
    for (int i = 0; i < 10; i++)
        count += dp[i][n];
 
    return count;
}

int main() {
    int n = 3;
    cout << countNonDecreasing(n);
    return 0;
}