Utils


int num = stoi("2");                    // String to Int, num = 2

string s = to_string(12345);            // Int to string, s = "12345"


// int to char, 8 -> '8'
char itoc(int number) {
   return char('0' + number);
}

// char to int, '8' -> 8
int ctoi(char c){
    return c - '0';
}

int gcd(int a, int b){
    if(a < b) return gcd(b,a);

    if(b == 0) return a;

    return gcd(b, a%b);
}


int NCR(int N, int R){
    int ans = 1;

    R = min(R, N-R);

    for(int r=1, n=N; r<=R; r++, n--){
        int g = gcd(ans,r);
        ans /= g;
        ans *= n;
        ans /= (r/g);
    }

    return ans;
}
    
// get ascii value of character

#include <iostream>
using namespace std;


int getAsciiValue(char c){
	return int(c);       // <------ you have to use this method
}

int main(int argc, char const *argv[])
{
	char char1 = 'a';
	char char2 = 'D';
	char char3 = '5';
	char char4 = '\n';


	cout << getAsciiValue(char1) << endl;   // 97
	cout << getAsciiValue(char2) << endl;	// 68
	cout << getAsciiValue(char3) << endl;   // 53 
	cout << getAsciiValue(char4) << endl;   // 10

	return 0;
}

Last updated