Skip to content

Ready-to-use VS Code configuration for competitive programming in different programming languages. Just write code, press Ctrl+Shift+B, and check your output!

License

Notifications You must be signed in to change notification settings

Zahid-Hasan-Mozumder/vs-code-competitive-programming-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

vs-code-competitive-programming-setup

A simple setup for C++ and Java competitive programming with automated testing.

πŸ“ Folder Structure

competitive-programming/
β”œβ”€β”€ cpp/
β”‚   β”œβ”€β”€ sol.cpp
β”‚   β”œβ”€β”€ input.txt
β”‚   β”œβ”€β”€ output.txt
β”‚   └── .vscode/tasks.json
└── java/
    β”œβ”€β”€ sol.java
    β”œβ”€β”€ input.txt
    β”œβ”€β”€ output.txt
    └── .vscode/tasks.json

πŸš€ Setup

Prerequisites

For C++:

  • Install MinGW-w64 (Windows) or GCC
  • Install C/C++ Extension in VS Code

For Java:

  • Install JDK 8+
  • Install Extension Pack for Java in VS Code

Installation

  1. Create the folder structure above
  2. Open cpp or java folder in VS Code
  3. Create .vscode/tasks.json with the config below
  4. Install the required extension

βš™οΈ Configuration

C++ (cpp/.vscode/tasks.json)

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile and run",
            "type": "shell",
            "command": "g++ -std=c++17 -o \"${fileBasenameNoExtension}.exe\" \"${file}\" && \"${fileBasenameNoExtension}.exe\" < input.txt > output.txt",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "shell": {
                    "executable": "cmd.exe",
                    "args": ["/d", "/c"]
                }
            }
        }
    ]
}

Java (java/.vscode/tasks.json)

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile and run",
            "type": "shell",
            "command": "cmd.exe",
            "args": [
                "/d",
                "/c",
                "javac \"${file}\" && java -cp \"${fileDirname}\" \"${fileBasenameNoExtension}\" < input.txt > output.txt"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "shell": {
                    "executable": "cmd.exe",
                    "args": ["/d", "/c"]
                }
            }
        }
    ]
}

πŸ’» Usage

  1. Write your code in sol.cpp or sol.java
  2. Add test cases in input.txt
  3. Press Ctrl+Shift+B
  4. Check output in output.txt

πŸ“ Templates

C++ Template

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t; cin >> t;
    while(t--) {
        // Your code here
    }
}

Java Template

import java.io.*;
import java.util.*;

public class sol {

    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int t = in.nextInt();
        while (t-- > 0) {
            /*
            Your code here
            
            int n = in.nextInt();
            int ans = 0;
            for (int i = 0; i < n; i++) {
                int cur = in.nextInt();
                ans += cur;
            }
            out.println(ans);
            */
        }
        out.close();
    }

    // FastReader class for fast i/o ----------------------------------------------
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

πŸ› Troubleshooting

"g++ is not recognized"

  • Add MinGW bin folder to system PATH
  • Verify: g++ --version

"javac is not recognized"

  • Add JDK bin folder to system PATH
  • Verify: javac -version

Output not updating

  • Check for compilation errors
  • Ensure input.txt exists
  • Close output.txt if open

πŸŽ₯ Video Tutorial

  • You can watch this video for better understanding.

🀝 Contributing

⭐ Show Your Support

  • If this setup helped you, please consider giving it a star! ⭐
  • It helps others discover this project and motivates me to maintain it.

πŸ“„ License

  • This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“§ Contact

About

Ready-to-use VS Code configuration for competitive programming in different programming languages. Just write code, press Ctrl+Shift+B, and check your output!

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published