Monday, June 21, 2021

Set up Sublime-Text for Competitive Coding | C/C++,Python

Hii everyone! Setting up sublime text for competitive coding is easy but not at the very first try. 

Today, your that first try will be made simpler and easier by bringing the right things in fron of you. This is specifically done for mac os x.

So let's get started.

1) C/C++

Step -1 : Create and save three files 

                1) input.in

                2) output.in

                3) hello.cpp / hello.c file 

Step - 2 : Install gcc(GNU Compiler Collection) by running the command below in the terminal.

Install gcc -

$ brew install gcc

If you already have gcc installed, check the version of gcc by 

$ gcc-10 -v

 OR

$ gcc-9 -v

 Now to install gtimeout, run the command

$ brew install coreutils

 Since we will require gtimeout which is a part of coreutils library, we are installing coreutils.

As a next step, create a new build system using the following steps.

Tools->Build System->New Build System

 Now copy the following code in the current file


{
"cmd" : ["g++-10 $file_name -o $file_base_name &&
 gtimeout 4s ./$file_base_name<inp.in>out.in"],
"selector" : "source.c,source.cpp",
"shell": true,
"working_dir" : "$file_path"

Now, Save the buile fie with any name your want with an extension '.sublime-build'

For example, C++.sublime-build

Now setup the column view,

1) View -> Layout -> Columns: 3

2) View -> Group -> Max Columns: 2

Here's how it will look,

Now you're all set to go!

Write some code in .cpp/.c file, select the build system as C++, the one which you just created and write the input in inp.in file and run the code.

You will see the output in out.in.

Final setup 


2) Python

For Python, if you already have created inp.in and out.in for C/C++, you don't need to create them again. And create the files if you have not already created them before.

Now, Create a .py file. For example, sample.py

1.Tools->Build System->New Build System

In the file, paste the code given below,

{
"cmd" : ["Python3 $file_name -o $file_base_name 4s ./$file_base_name<inp.in>out.in"],
"selector" : "source.py",
"shell": true,
"working_dir" : "$file_path"
}

Now you can save the build file with any name like Python3.sublime-build. 

Run the code in sample.py code, write th input in inp.in file and you will see the output in out.in






No comments:

Post a Comment

Time

  A brief look at time......  

Popular Posts