Coder Social home page Coder Social logo

algorithms-snippets's Introduction

Algorithms-Snippets

Contains build systems (cpp build systems) and competitive coding algorithms snippet for sublime text 3. Please contribute (add new algorithms or improve existing algorithms) to make it perfect.

Intention

The main intention behind this repository is to help beginners in setting up cpp enviroment for competitive coding and making them familiar with build-systems and snippets to improve their coding speed.

Every competitive programmer faced one question at some point of time that which is best IDE? which IDE use to do competitive programming?.

Here is the answer, "Sublime Text 3" is one of the best IDE (might not best but definitely one of the best IDEs after all its all depends on coders choice), so here are some tricks in sublime text 3 for fast and efficient competitive programming.

Download And Setup

  • First of all check whether gcc/g++ compiler is installed in your machine or not, and if not then install it.

    For Linux - https://www.youtube.com/watch?v=mqHdXCMmOXM

    For Windows- https://www.youtube.com/watch?v=r3FJta3RD0s

  • You can download sublime text 3 from https://www.sublimetext.com/3.

  • To enable sidebar(sidebar show all open files/folders make navigation between files easy) go to

    View > Sidebar > Show Sidebar

  • To add folder to sidebar(after adding folder to sidebar, all files inside folder will be displayed in sidebar) go to

    Project > Add Folder To Project > Select Folder

Adding Build Systems

Build System - 1

  • To compile and run cpp code from sublime text 3 itself on click of "ctrl+shift+B" we have to create build system. In this Build System cpp code will read input from file "input.txt" and will write output to file "output.txt".

    Here is the screenshot of how it will looks and works -

  • First of all create two files named as "input.txt" and "output.txt" in current working directory(folder containing cpp file).

    Note - The cpp file you compile and run must be in same folder as both of this file else it will give error as build system will not found file to read input and write output of cpp code.

    To provide input to cpp code you have to write input in file "input.txt" and code will write output to "output.txt". To make it(providing input and reading output) easy, we will always keep "input.txt" and "output.txt" open as shown in above screenshots. To open such layout select

    • View > Layout > Columns: 3
    • View > Groups > Max Columns: 2
    • Then open "input.txt" in upper right window and "output.txt" in lower right window and resize them according to your prefrences.

    I will suggest you to keep "input.txt" and "output.txt" always open in upper right and lower right windows while open your cpp code in left window and all your logic goes there.

  • We are done with taking input and writing output now we have to write script to compile and run cpp code.

    • To create build system go to

      Tools > Build System > New Build System

      • For Linux

        Copy paste given code and save it with name linux_cpp_1.sublime-build

        {
          "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\" <input.txt >output.txt",
          "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
          "working_dir": "${file_path}",
          "selector": "source.c, source.c++, source.cpp",
        }
        
      • For Windows

        Copy paste given code and save it with name windows_cpp.sublime-build

        {
          "cmd": ["g++.exe", "${file}", "-o", "${file_base_name}.exe", "&&" , "${file_base_name}.exe<input.txt>output.txt"],
          "shell":true,
          "working_dir":"$file_path",
          "selector": "source.c, source.c++, source.cxx, source.cpp", 
        }
        
    • To enable build system select

      • For Linux

        Tools > Build System > linux_cpp_1

      • For windows

        Tools > Build System > windows_cpp

  • To compile and run code, press "ctrl+shift+B".

    Note- while compiling and running code(when you press "ctrl+shift+B"), the tab/window containing cpp code should be active because build system will try to compile active tab/window and if input.txt/output.txt will be active then it will try to compile and run it and it will give error.

Build System - 2 (For Linux Only)

  • To compile and run cpp code in terminal from sublime text 3 on click of "ctrl+shift+B" we have to create build system.

    Here is the screenshot of how it will looks and works -

    • To create build system select

      Tools > Build System > New Build System

    • copy paste given code and save it with name linux_cpp_2.sublime-build

      { 
        "cmd": ["g++", "$file", "-o", "${file_path}/${file_base_name}"], 
        "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", 
        "working_dir": "${file_path}", 
        "selector": "source.c, source.c++, source.cxx, source.cpp", 
        "variants": 
        [ 
          { 
            "name": "Run", 
            "shell": true, 
            "cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo;echo Press ENTER to continue; read line;exit; exec bash\"'"] 
          } 
        ] 
      }
      
    • To enable build system select

      Tools > Build System > linux_cpp_2

  • To compile code

    Press "ctrl+shift+B" and then select "linux_cpp_2".

    To run compiled code

    Press "ctrl+shift+B" and then select "linux_cpp_2 - Run".

    Note- while compiling and running code(when you press "ctrl+shift+B"), the tab/window containing cpp code should be active because build system will try to compile active tab/window and if input.txt/output.txt will be active then it will try to compile and run it and it will give error.

Adding Snippets

algorithms-snippets's People

Contributors

brijeshpanara24 avatar shreyansh08 avatar

Watchers

James Cloos 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.