A simple setup for C++ and Java competitive programming with automated testing.
competitive-programming/
βββ cpp/
β βββ sol.cpp
β βββ input.txt
β βββ output.txt
β βββ .vscode/tasks.json
βββ java/
βββ sol.java
βββ input.txt
βββ output.txt
βββ .vscode/tasks.json
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
- Create the folder structure above
- Open
cpporjavafolder in VS Code - Create
.vscode/tasks.jsonwith the config below - Install the required extension
{
"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"]
}
}
}
]
}{
"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"]
}
}
}
]
}- Write your code in
sol.cpporsol.java - Add test cases in
input.txt - Press
Ctrl+Shift+B - Check output in
output.txt
#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
}
}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;
}
}
}"g++ is not recognized"
- Add MinGW
binfolder to system PATH - Verify:
g++ --version
"javac is not recognized"
- Add JDK
binfolder to system PATH - Verify:
javac -version
Output not updating
- Check for compilation errors
- Ensure
input.txtexists - Close
output.txtif open
- You can watch this video for better understanding.
- Contributions are welcome! Please check out the Contributing Guide to get started.
- If this setup helped you, please consider giving it a star! β
- It helps others discover this project and motivates me to maintain it.
- This project is licensed under the MIT License - see the LICENSE file for details.
- Have questions or suggestions? Feel free to open an issue!