├── .gitignore ├── input.txt ├── output.txt ├── preview.png ├── main.py ├── README.md ├── main.cpp └── Main.java /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.class 3 | main.exe -------------------------------------------------------------------------------- /input.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 -------------------------------------------------------------------------------- /output.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grandolf49/competitive-programming-vscode-template/HEAD/preview.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # Remove these 2 lines while submitting your code online 4 | sys.stdin = open('input.txt', 'r') 5 | sys.stdout = open('output.txt', 'w') 6 | 7 | 8 | def solve(test): 9 | # Do your thing here :) 10 | print(test) 11 | 12 | 13 | def main(): 14 | test_case = int(input()) 15 | for test in range(test_case): 16 | solve(test + 1) 17 | 18 | 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Competitive Programming Template for [VS Code](https://code.visualstudio.com/) 2 | A Competitive Programming setup for C++, Java, Python languages on Visual Studio Code. I have written a detailed **[Medium Article](https://medium.com/@chinmaykulkarni8/how-to-setup-visual-studio-code-for-c-c-java-python-competitive-programming-angular-22fdc9b1f4c6?sk=ba78631b9b56823fb375e967453c04e7)** on how to setup VS Code for Competitive Programming. Do check it out! 3 | 4 | ## Preview 5 | ![preview](https://github.com/Grandolf49/competitive-programming-vscode-template/blob/master/preview.png) 6 | 7 | ## How to use 8 | 1. Clone the repository. 9 | 2. Open the folder in **Visual Studio Code** 10 | 3. Choose the language of your choice. 11 | 4. Add the input to **input.txt** file. 12 | 5. Run the code! 13 | 6. Output will be generated in **output.txt** file. 14 | 15 | ## Points to remember 16 | 1. All the three files **main.cpp**, **Main.java**, **main.py** contain a template code which first accepts the number of testcases and calls a function **solve()** where you can write your code. 17 | 2. If the input format is different from this one, please make necessary changes to the **main()** function. 18 | 19 | ## Contributions 20 | All contributions are welcomed through issue tracker and pull requests. 21 | - Please feel free to create issues if you are facing some errors while running the sample templates. I spent a lot of time fixing things so hopefully I can help you resolve them :) 22 | - If you find better header functions our better IO techniques, do contribute! 23 | - If you can add language templates for other languages, do contribute! 24 | 25 | To contribute follow the steps below: 26 | 1. Fork the repository. 27 | 2. Commit the changes to your forked repository. 28 | 3. Create a PR to master branch of this repository. 29 | 30 | ### Happy Coding! 31 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define FOR(i, j, k, in) for (int i = j; i < k; i += in) 5 | #define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in) 6 | #define REP(i, j) FOR(i, 0, j, 1) 7 | #define RREP(i, j) RFOR(i, j, 0, 1) 8 | 9 | #define INF (int)1e9 10 | #define PI 3.1415926535897932384626433832795 11 | #define MOD 1000000007 12 | 13 | typedef long long ll; 14 | typedef unsigned long long ull; 15 | 16 | typedef vector vi; 17 | typedef vector vvi; 18 | typedef vector vl; 19 | typedef vector vvl; 20 | typedef vector vc; 21 | typedef vector vvc; 22 | typedef pair pii; 23 | typedef pair pll; 24 | typedef pair pss; 25 | typedef map mii; 26 | typedef unordered_map umap_ii; 27 | typedef unordered_map umap_si; 28 | 29 | /** 30 | * Limits in C++ for reference 31 | * _____________________________________________________________________________________ 32 | * |Sr| Macro Name | Description | Value 33 | * |No|____________|_________________________________|__________________________________ 34 | * |1.| ULLONG_MAX | Maximum value unsigned long long| 18,446,744,073,709,551,615 (10^20) 35 | * |2.| LLONG_MAX | Maximum value long long | 9,223,372,036,854,775,807 (10^19) 36 | * |3.| LLONG_MIN | Minimum value long long |-9,223,372,036,854,775,808 -1*(10^19) 37 | * |4.| INT_MAX | Maximum value int | 2,147,483,647 (10^10) 38 | * |5.| INT_MIN | Minimum value int |-2,147,483,648 (10^10) 39 | */ 40 | 41 | void solve(ll test_case) 42 | { 43 | // Do your thing here :) 44 | cout << test_case << "\n"; 45 | } 46 | 47 | int main() 48 | { 49 | #ifndef ONLINE_JUDGE 50 | freopen("input.txt", "r", stdin); 51 | freopen("output.txt", "w", stdout); 52 | #endif 53 | ios_base::sync_with_stdio(false); 54 | cin.tie(NULL); 55 | 56 | ll t, t1 = 0; 57 | cin >> t; 58 | while (t1 < t) 59 | { 60 | solve(t1 + 1); 61 | t1++; 62 | } 63 | } -------------------------------------------------------------------------------- /Main.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileInputStream; 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.PrintStream; 7 | import java.util.InputMismatchException; 8 | 9 | public class Main { 10 | 11 | static final File ip = new File("input.txt"); 12 | static final File op = new File("output.txt"); 13 | static InputReader in; 14 | 15 | static { 16 | try { 17 | System.setOut(new PrintStream(op)); 18 | System.setIn(new FileInputStream(ip)); 19 | } catch (Exception e) { 20 | } 21 | 22 | in = new InputReader(System.in); 23 | } 24 | 25 | /*** 26 | * Write your code in this function! Input: Use InputReader "in" for reading 27 | * data. Output: Use System.out.println() to write output to file 28 | */ 29 | private static void solve(int t1) { 30 | int n = in.readInt(); 31 | System.out.println(n); 32 | } 33 | 34 | public static void main(String[] args) throws FileNotFoundException { 35 | 36 | int t = in.readInt(); 37 | int t1 = 1; 38 | while (t1 <= t) { 39 | solve(t1); 40 | t1++; 41 | } 42 | } 43 | 44 | /** 45 | * A class for Fast Input 46 | */ 47 | static class InputReader { 48 | private InputStream stream; 49 | private byte[] buf = new byte[1024]; 50 | private int curChar; 51 | private int numChars; 52 | private SpaceCharFilter filter; 53 | 54 | public InputReader(InputStream stream) { 55 | this.stream = stream; 56 | } 57 | 58 | public int read() { 59 | if (numChars == -1) 60 | throw new InputMismatchException(); 61 | if (curChar >= numChars) { 62 | curChar = 0; 63 | try { 64 | numChars = stream.read(buf); 65 | } catch (IOException e) { 66 | throw new InputMismatchException(); 67 | } 68 | if (numChars <= 0) 69 | return -1; 70 | } 71 | return buf[curChar++]; 72 | } 73 | 74 | public int readInt() { 75 | int c = read(); 76 | while (isSpaceChar(c)) 77 | c = read(); 78 | int sgn = 1; 79 | if (c == '-') { 80 | sgn = -1; 81 | c = read(); 82 | } 83 | int res = 0; 84 | do { 85 | if (c < '0' || c > '9') 86 | throw new InputMismatchException(); 87 | res *= 10; 88 | res += c - '0'; 89 | c = read(); 90 | } while (!isSpaceChar(c)); 91 | return res * sgn; 92 | } 93 | 94 | public String readString() { 95 | int c = read(); 96 | while (isSpaceChar(c)) 97 | c = read(); 98 | StringBuilder res = new StringBuilder(); 99 | do { 100 | res.appendCodePoint(c); 101 | c = read(); 102 | } while (!isSpaceChar(c)); 103 | return res.toString(); 104 | } 105 | 106 | public boolean isSpaceChar(int c) { 107 | if (filter != null) 108 | return filter.isSpaceChar(c); 109 | return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; 110 | } 111 | 112 | public String next() { 113 | return readString(); 114 | } 115 | 116 | } 117 | 118 | public interface SpaceCharFilter { 119 | public boolean isSpaceChar(int ch); 120 | } 121 | } 122 | --------------------------------------------------------------------------------