Code Monkey home page Code Monkey logo

cppmaster's Introduction

Quick Recipes for Problem Solving

CONTENTS

Snippets

Snippets

Data Structures
Basics
Graphs
Strings
Maths
Algorithm Templates
Python Stuff
Miscellaneous
General Thoughts

Something to remember is many STL functions can be applied for several containers. Remember this. Eg: count() can be used for vector and strings like Counter() in python.
Like that find_end, find_first_of can be applied.

Some key things to remember when starting off:

  1. begin() and end() are used for iterators

  2. front() and back() are used for - looking up

  3. unordered_map is faster

  4. map sorts by key by default

  5. iterator to index -> it - v.begin() instead of std::distance()
    https://stackoverflow.com/questions/2152986/what-is-the-most-effective-way-to-get-the-index-of-an-iterator-of-an-stdvector

  6. Rememeber these 2 styles Parsing through a vector and comparing each element

Case1 : Here you go with the iterator approach - and this is how you compare.

for (auto it = words.begin(); it != words.end(); ++it){
            if ((*it).compare(word1) == 0)
               pos = it - words.begin()

Case 2: You go with the routine approach:

    for(int i = 0; i < words.size(); i++) {
        if (words[i] == word1)
  1. There are 25 prime numbers from 1 to 100.

  2. Something to remember here is that:
    all these functions - take iterators as I/P's.
    But iterators are more like pointers and they can be incremented or decremented

  3. So this concept called ptr is being used here, so that it can be re-used everywhere else. Guess that's this has been implemented in C++ example is: count() - for compile time polymorphism Like templates

Useful References 1. https://medium.com/logicalbee/c-stl-algorithms-cheat-sheet-d92f986abe14 2. https://www.cs.mun.ca/~dchurchill/pc/pdf/algorithms_1.pdf 3. https://medium.com/@13dipty/bfs-implementation-in-c-495931323710 4. https://medium.com/cheat-sheets/cheat-sheet-for-competitive-programming-with-c-f2e8156d5aa9 5. https://rohanrajpal.com/competitive%20programming/2020/06/20/cpp-cheat-sheet.html 6. https://www.geeksforgeeks.org/c-tricks-competitive-programming-c-11/ 7. https://www.codementor.io/@satwikkansal/stl-cheatsheet-for-competitive-programming-arrlk3rqn 8. https://stackoverflow.com/questions/1041620/whats-the-most-efficient-way-to-erase-duplicates-and-sort-a-vector

cppmaster's People

Contributors

hariharanragothaman avatar

Stargazers

Lester Wang avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.