├── Template.cpp └── README.md /Template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define cin(vec) for(auto& i : vec) cin >> i 6 | #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++); 7 | #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n"; 8 | #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++); 9 | #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " " << s << "\n"; 10 | #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n"; 11 | #define fixed(n) fixed << setprecision(n) 12 | #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0)) 13 | #define fill(vec, value) memset(vec, value, sizeof(vec)); 14 | #define Num_of_Digits(n) ((int)log10(n) + 1) 15 | #define mod_combine(a, b, m) (((a % m) * (b % m)) % m) 16 | #define all(vec) vec.begin(), vec.end() 17 | #define rall(vec) vec.rbegin(), vec.rend() 18 | #define sz(x) int(x.size()) 19 | #define debug(x) cout << #x << ": " << (x) << "\n"; 20 | #define fi first 21 | #define se second 22 | #define Pair pair < int, int > 23 | #define ll long long 24 | #define ull unsigned long long 25 | #define Mod 1'000'000'007 26 | #define OO 2'000'000'000 27 | #define EPS 1e-9 28 | #define PI acos(-1) 29 | 30 | void Fast_IO(){ 31 | ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 32 | #ifndef ONLINE_JUDGE 33 | freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); 34 | #endif 35 | } 36 | 37 | void Solve(){ 38 | 39 | } 40 | 41 | int main(){ 42 | Fast_IO(); 43 | int t = 1; 44 | //cin >> t; 45 | while(t--) 46 | Solve(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VS-Code-for-CP 2 | 3 | For competitive programming, I use Linux dual booted alongside Windows. My favorite IDE is VS Code and it's perfect for short codes in CP. 4 | 5 |
6 | 7 | ### [Tutorial Video](https://www.youtube.com/watch?v=8UvUyVjpWdU) 8 | 9 |
10 | 11 | 1. **Install C++** 12 | 13 | ``` 14 | sudo apt install g++ 15 | ``` 16 | 17 | 2. **Instal VS Code** 18 | 19 | ``` 20 | wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg 21 | sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ 22 | sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' 23 | rm -f packages.microsoft.gpg 24 | ``` 25 | ``` 26 | sudo apt install apt-transport-https 27 | sudo apt update 28 | sudo apt install code 29 | ``` 30 | 31 | 3. **Install C++ on VS CODE** 32 | 33 | - Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. 34 | 35 | ``` 36 | ext install ms-vscode.cpptools-extension-pack 37 | ``` 38 | 39 | 4. **Install C/C++ Compile Run** 40 | 41 | - Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. 42 | 43 | ``` 44 | ext install danielpinto8zz6.c-cpp-compile-run 45 | ``` 46 | 47 | 5. **Install Code Runner on VS CODE** 48 | 49 | - Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. 50 | 51 | ``` 52 | ext install formulahendry.code-runner 53 | ``` 54 | 55 | 6. **Change Settings of Code Runner** 56 | 57 | - Open `Settings` in vscode (ctrl + comma) 58 | - Search on `Run Code Configuration` 59 | - [x] on `Clear Previous Output` 60 | - [x] on `Run In Terminal` 61 | - [x] on `Save All Files Before Run` 62 | - Don't Close `Settings` because we will use it in the next step 63 | 64 | 7. **Change Executor Map of Code Runner** 65 | - Click on `Edit in settings json` at `Executor Map By File Extension` 66 | - at `code-runner.executorMap` edit in cpp label 67 | - choose one flag from these and put it in cpp label: 68 | - this command for execute the file with cp flags and make the code terminate after one second 69 | - `"cd $dir && g++ -std=c++2a -Wshadow -Wall -o -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG $fileName -o $fileNameWithoutExt && timeout -k 0 1s $dir$fileNameWithoutExt"` 70 | - this command for execute the file with cp flags only 71 | - `"cd $dir && g++ -std=c++2a -Wshadow -Wall -o -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"` 72 | - this command for execute the file with cp flags but less debuger than the above one 73 | - `"cd $dir && g++ -std=c++2a -Wshadow -Wall -o "%e" "%f" -O2 -Wno-unused-result $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"` 74 | - this flag for Windows 75 | - `"cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"` 76 | - this command for input and output from files with flags 77 | - `"cd $dir && g++ -std=c++2a -Wshadow -Wall -o -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG $fileName -o $fileNameWithoutExt && timeout -k 0 1s $dir$fileNameWithoutExt < input.txt > output.txt && rm $dir$fileNameWithoutExt"` 78 | - this command for input and output from files without flags 79 | - `"cd $dir && g++ -std=c++2a $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt < input.txt > output.txt && rm $dir$fileNameWithoutExt"` 80 | 81 | 8. **Use Files instead of terminal** 82 | - We will use freopen and files txt to take input and output from use instead of terminal 83 | - First we should put this function in our code 84 | ```C++ 85 | void Fast_IO(){ 86 | ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 87 | #ifndef ONLINE_JUDGE 88 | freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); 89 | #endif 90 | } 91 | ``` 92 | - Create text file and name it `input.txt` 93 | 94 | 9. **Split Screen to make the view better for you** 95 | - The image in below will show you the view after splitting it. 96 | - ![Screenshot from 2022-02-05 21-00-34](https://user-images.githubusercontent.com/63050133/152655170-89857fb7-4f8a-4425-9f54-55503d8d4b62.png) 97 | 98 | 99 | **Enjoy now with you CP Enviroment** 100 | 101 | 102 | ---- 103 | 104 |


105 | 106 | ## Optional things to do 107 | 108 | **Install Atom One Dark Theme** 109 | 110 | - Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. 111 | 112 | ``` 113 | ext install akamud.vscode-theme-onedark 114 | ``` 115 | 116 | **Install Bracket Pair Colorizer** 117 | 118 | - Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. 119 | 120 | ``` 121 | ext install CoenraadS.bracket-pair-colorizer 122 | ``` 123 | 124 | **Install Easy icon theme** 125 | 126 | - Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. 127 | 128 | ``` 129 | ext install jamesmaj.easy-icons 130 | ``` 131 | 132 | 133 | **Make Your Snippet** 134 | 135 | - You can go to [this site](https://snippet-generator.app/) and make a snippet for you 136 | 137 | - After that you can copy the snippet and insert it in your vscode to call it in anytime 138 | 139 |


140 | 141 | ### You can use my template for competitve programming with cpp from [here](https://github.com/7oSkaaa/VS-Code-for-CP/blob/main/Template.cpp) 142 | 143 |


144 | 145 |
146 | 147 | You can make two run commands with shortcut 148 | 149 | - Run with flags 150 | - Run without flags 151 | 152 | ``` 153 | - Go to keyboard Shortcuts or `Ctrl + k + s` 154 | - search on code-runner 155 | - make shortcut for `code-runner.run` for Run with flags 156 | - make shortcut for `code-runner.runCustomCommand` for Run without flags 157 | ``` 158 | 159 |
160 | 161 | ### This is settings.json file if you want to add it's content to your settings.json file 162 | 163 | ```json 164 | { 165 | "code-runner.executorMap": { 166 | "javascript": "node", 167 | "java": "cd $dir && javac $fileName && java $fileNameWithoutExt", 168 | "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 169 | "cpp": "cd $dir && g++ -std=c++2a -Wshadow -Wall -o -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG $fileName -o $fileNameWithoutExt && timeout -k 0 1s $dir$fileNameWithoutExt < input.txt > output.txt && rm $dir$fileNameWithoutExt", 170 | "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 171 | "php": "php", 172 | "python": "python3 -u", 173 | "perl": "perl", 174 | "perl6": "perl6", 175 | "ruby": "ruby", 176 | "go": "go run", 177 | "lua": "lua", 178 | "groovy": "groovy", 179 | "powershell": "powershell -ExecutionPolicy ByPass -File", 180 | "bat": "cmd /c", 181 | "shellscript": "bash", 182 | "fsharp": "fsi", 183 | "csharp": "scriptcs", 184 | "vbscript": "cscript //Nologo", 185 | "typescript": "ts-node", 186 | "coffeescript": "coffee", 187 | "scala": "scala", 188 | "swift": "swift", 189 | "julia": "julia", 190 | "crystal": "crystal", 191 | "ocaml": "ocaml", 192 | "r": "Rscript", 193 | "applescript": "osascript", 194 | "clojure": "lein exec", 195 | "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt", 196 | "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt", 197 | "racket": "racket", 198 | "scheme": "csi -script", 199 | "ahk": "autohotkey", 200 | "autoit": "autoit3", 201 | "dart": "dart", 202 | "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt", 203 | "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt", 204 | "haskell": "runhaskell", 205 | "nim": "nim compile --verbosity:0 --hints:off --run", 206 | "lisp": "sbcl --script", 207 | "kit": "kitc --run", 208 | "v": "v run", 209 | "sass": "sass --style expanded", 210 | "scss": "scss --style expanded", 211 | "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css", 212 | "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 213 | "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 214 | "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 215 | "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" 216 | }, 217 | "C_Cpp.default.cppStandard": "c++23", 218 | "C_Cpp.default.compileCommands": "g++ -std=c++2a -Wshadow -Wall -o \"%e\" \"%f\" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG", 219 | "c-cpp-compile-run.cpp-flags": "-std=c++2a -Wshadow -Wall -o -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG", 220 | "settingsSync.ignoredSettings": [ 221 | "-C_Cpp.default.compileCommands" 222 | ], 223 | "code-runner.customCommand": "cd $dir && g++ -std=c++2a $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt < input.txt > output.txt && rm $dir$fileNameWithoutExt", 224 | "[plaintext]": { 225 | "editor.defaultFormatter": "GlenBuktenica.unicode-substitutions" 226 | } 227 | } 228 | ``` 229 | --------------------------------------------------------------------------------