Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя devildeweller

Автор devildeweller, история, 10 месяцев назад, По-английски

Many of you have used a debug tool or want to run some code locally but don't want it to run on other devices or platforms. Mainly competitive programmers use something like this ->

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define dbg(...) ; 
#define debug(...) ; 
#define crndl ; 
#endif

and it works for online platforms that have defined online judges.

But what if we want to run code on other websites without defined online judges or devices without removing the code every time? I face this problem and it is annoying. Before sharing code you have to remove some of the lines of the codes.

Now, I recently came across the solution by defining your own macro you do not have to think while submitting code or sharing your code.

Instead of using #ifndef ONLINE_JUDGE you can use ifdef (any_name).

EX->

#ifdef Loki
#include "debug.h"
#else
#define dbg(...) ; 
#define debug(...) ; 
#define crndl ; 
#endif

Now to run this code in your device you have two options either running by command or changing the build system.

Command-> g++ -DLoki ex.cpp -o ex Basically you have to add -D(name_you_used) after g++.

For Linux build system ->

{
"cmd" : ["g++ -DLoki -std=c++17 $file_name -o $file_base_name && timeout 5s ./$file_base_name<inputf.in>outputf.in"], 
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path"
}

For Windows build system ->

{
    "cmd": ["g++.exe", "-DLoki", "-std=c++17", "${file}",
            "-o", "${file_base_name}.exe",
            "&&", "${file_base_name}.exe<inputf.in>outputf.out"],
    "shell":true,
    "working_dir":"$file_path",
    "selector":"source.cpp"
}

For Mac build system ->

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

Hope this will help you. Have a great day.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +16
  • Проголосовать: не нравится