Skip to content
richagithub edited this page Jul 27, 2020 · 53 revisions

Welcome to the Codes wiki!

Why-cant-we-use-double-pointer-to-represent-two-dimensional-arrays? twoDArray.txt
Fast I/O Operation https://github.com/richagithub/Codes/blob/master/Fast_I%5CO.txt

 ios_base::sync_with_stdio(false);        
 cin.tie(NULL);

Tokenize a sting in c++? StringTokenizer.txt
How to scan integers until newline? answer
Find Largest and second largest int with O(n) answer
Sort a string or char array ? Answer
Permute given String and print all in lexicographically increasing order. TUTORIAL
Calculate power of 2 upto 100000 . program.cpp recursion dynamic programming
Input/Output with File in C++ codechef discuss

freopen("input.txt","r",stdin);//redirects standard input    
freopen("output.txt","w",stdout);//redirects standard output  

If error comes for 'To disable deprecation' in VS , then use:
_CRT_SECURE_NO_WARNINGS defines must be placed before headers such as stdio.h are included, otherwise they're useless.

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    ...

Operator Overloading
STL
Trick - count digits in a factorial

LaTreeX - online free TREE-PDF generatorLaTreeX - online free TREE-PDF generator
Recipe-to-improve-your-programmingmdotsabouri.blogspot.com
BFS in Grid Shortest Path in matrix using BFS
Udemy video downloading by youtube-dl pip of python:

PS D:\UDEMY\UDEMY ANGULAR> youtube-dl -u multipremp@gmail.com -p Ayranika@2017 -cio "%(playlist_index)s-%(title)s.
(ext)s" https://www.udemy.com/the-complete-angular-master-class/learn/v4/content

REF: https://stackoverflow.com/questions/41931230/how-to-download-udemy-videos

Notes

list for cp https://github.com/lnishan/awesome-competitive-programming

  • Strings
  • Graphs

BitMasking

Sr Challenge Solution Tags
1 winning-lottery-ticket solution.cpp hackerrank hiring

Strings

Sr Challenge Solution Tags
1 Seperate the Numbers solution.cpp
2 Weighted Unifrom Strings solution.cpp
3
4

Graphs

Sr Challenge Solution Tags
1 Even Tree solution.cpp
2 Breadth First Search: Shortest Reach solution.cpp
3 Red Knight's Shortest Path WorldCodeSprint12.cpp
4 Coloring a Tree 902B.cpp dfs

Greedy

Sr Challenge Solution Tags
1 buy-maximum-stocks solution.cpp

Dynamic Programming

Sr Challenge Solution Tags
1 trader-profit solution.cpp

Codechef

Sr Challenge Solution Tags
1 Chef and Sign Sequence july17.cpp
2 Beautiful Array COOK89.cpp Modular Operation Greedy Algorithms

Operator Overloading

A simple and complete example

#include<iostream>
using namespace std; 
class Complex {
private:
    int real, imag;
public:
    Complex(int r = 0, int i =0)  {real = r;   imag = i;}
    // This is automatically called when '+' is used with
    // between two Complex objects
    Complex operator + (Complex const &obj) {
         Complex res;
         res.real = real + obj.real;
         res.imag = imag + obj.imag;
         return res;
    }
    void print() { cout << real << " + i" << imag << endl; }
};
int main()
{
    Complex c1(10, 5), c2(2, 4);
    Complex c3 = c1 + c2; // An example call to "operator+"
    c3.print();
}  

Output: 12 + i9

Global Operator Function

class Complex {
private:
    int real, imag;
public:
    Complex(int r = 0, int i =0)  {real = r;   imag = i;}
    void print() { cout << real << " + i" << imag << endl; }
 
// The global operator function is made friend of this class so
// that it can access private members
friend Complex operator + (Complex const &, Complex const &);
};
 
 
Complex operator + (Complex const &c1, Complex const &c2)
{
     return Complex(c1.real + c2.real, c1.imag + c2.imag);
}

Following is the list of operators that cannot be overloaded. . (dot) :: ?: sizeof

STL

log base 10 - log10(<number>)
floor - floor(x)

Tricks-1

Count digits in factorial -https://www.geeksforgeeks.org/count-digits-factorial-set-1/

We know,
log(a*b) = log(a) + log(b)

Therefore
log( n! ) = log(123....... * n)
= log(1) + log(2) + ........ +log(n)

Now, observe that the floor value of log base
10 increased by 1, of any number, gives the
number of digits present in that number.

Hence, output would be : floor(log(n!)) + 1.

Clone this wiki locally